Skip to content

Commit ff6615d

Browse files
fix(mobile): every header scroll view blurs under the Duo's vertical bar
UIKit draws the header's scroll-edge blur inside the scroll view, and Duo columns pad their content away from the vertical bar, so the blur stopped at the bar on every screen. NativeScrollViewMarker, the one way to register a header scroll view, now wraps it in a native view that widens the scroll view under any side safe area its column pads away and leaves the content where it was. Columns keep padding everything else, so no screen can put content under the bar, and a new screen gets the blur by registering its scroll view at all. Lint rejects importing ScrollViewMarker from react-native-screens anywhere else. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 59ca212 commit ff6615d

10 files changed

Lines changed: 172 additions & 7 deletions

File tree

‎apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public final class T3NativeControlsModule: Module {
4848
Events("onMetricsChange")
4949
}
5050

51+
View(T3ScrollEdgeBleedView.self) {
52+
ViewName("ScrollEdgeBleed")
53+
}
54+
5155
AsyncFunction("presentVideo") { (url: URL, title: String, sourceIdentifier: String, identifier: String, promise: Promise) in
5256
try self.presentVideo(
5357
url: url,
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import ExpoModulesCore
2+
import UIKit
3+
4+
/// Wraps a screen's header scroll view. Where a column pads its content away from a side safe
5+
/// area (the iPhone Duo's vertical bar), this widens the scroll view under that band. UIKit draws
6+
/// the header's scroll-edge effect inside the scroll view, so the blur reaches the bar like in the
7+
/// system apps while the content stays in the safe area. Everything happens in UIKit layout, so
8+
/// folds move the blur and the content together.
9+
final class T3ScrollEdgeBleedView: ExpoView {
10+
// Fabric recycles scroll views, so everything changed here is put back before this view leaves
11+
// the window, which unmounting does before any recycling.
12+
private var scrollView: UIScrollView?
13+
private var container: UIView?
14+
private var bleed = UIEdgeInsets.zero
15+
/// React Native's clipping, saved while bleeding. React Native only rewrites it when the
16+
/// `overflow` style changes, so it stays off while bleeding.
17+
private var containerClipped: Bool?
18+
19+
deinit {
20+
MainActor.assumeIsolated { detach() }
21+
}
22+
23+
override func didMoveToWindow() {
24+
super.didMoveToWindow()
25+
if window == nil { detach() } else { setNeedsLayout() }
26+
}
27+
28+
override func didAddSubview(_ subview: UIView) {
29+
super.didAddSubview(subview)
30+
setNeedsLayout()
31+
}
32+
33+
override func willRemoveSubview(_ subview: UIView) {
34+
if let scrollView, scrollView.isDescendant(of: subview) { detach() }
35+
super.willRemoveSubview(subview)
36+
}
37+
38+
override func layoutSubviews() {
39+
super.layoutSubviews()
40+
guard window != nil, let found = findScrollView(), let parent = found.superview else { return }
41+
if found !== scrollView {
42+
detach()
43+
scrollView = found
44+
container = parent
45+
}
46+
bleed = flushSafeAreaBand()
47+
apply()
48+
}
49+
50+
/// The side safe areas this view sits flush against: an ancestor padded its content away from
51+
/// them. Only those bands are bled into, so a screen with its own margins is left alone.
52+
private func flushSafeAreaBand() -> UIEdgeInsets {
53+
var ancestor = superview
54+
while let view = ancestor {
55+
let insets = view.safeAreaInsets
56+
if insets.left > 0 || insets.right > 0 {
57+
let frame = convert(bounds, to: view)
58+
let left = insets.left > 0 && abs(frame.minX - insets.left) < 0.5 ? insets.left : 0
59+
let right = insets.right > 0 && abs(view.bounds.maxX - insets.right - frame.maxX) < 0.5
60+
? insets.right : 0
61+
return UIEdgeInsets(top: 0, left: left, bottom: 0, right: right)
62+
}
63+
ancestor = view.superview
64+
}
65+
return .zero
66+
}
67+
68+
/// Widening to the right leaves the content in place. Widening to the left moves it with the
69+
/// frame, so a left inset and offset put it back.
70+
private func apply() {
71+
guard let scrollView, let container else { return }
72+
// React Native sizes the scroll view's component view; the UIScrollView inside follows it by
73+
// autoresizing, so the widened frame survives React Native's own layout updates.
74+
let frame = container.bounds.inset(by: UIEdgeInsets(top: 0, left: -bleed.left, bottom: 0, right: -bleed.right))
75+
if scrollView.frame != frame { scrollView.frame = frame }
76+
if bleed == .zero {
77+
if let clipped = containerClipped {
78+
containerClipped = nil
79+
container.layer.masksToBounds = clipped
80+
}
81+
} else if container.layer.masksToBounds {
82+
// The component view clips to its own bounds, which would cut the widened scroll view back.
83+
// The scroll view itself still clips its content.
84+
containerClipped = containerClipped ?? true
85+
container.layer.masksToBounds = false
86+
}
87+
var inset = scrollView.contentInset
88+
if inset.left != bleed.left {
89+
inset.left = bleed.left
90+
scrollView.contentInset = inset
91+
}
92+
var indicators = scrollView.verticalScrollIndicatorInsets
93+
if indicators.right != bleed.right {
94+
indicators.right = bleed.right
95+
scrollView.verticalScrollIndicatorInsets = indicators
96+
}
97+
let x = -scrollView.adjustedContentInset.left
98+
if scrollView.contentOffset.x != x {
99+
scrollView.contentOffset = CGPoint(x: x, y: scrollView.contentOffset.y)
100+
}
101+
}
102+
103+
private func detach() {
104+
guard scrollView != nil else { return }
105+
bleed = .zero
106+
apply()
107+
scrollView = nil
108+
container = nil
109+
}
110+
111+
/// The scroll view sits a fixed few levels down (marker, React Native's scroll view component);
112+
/// never walk into a scroll view's content.
113+
private func findScrollView() -> UIScrollView? {
114+
var level: [UIView] = subviews
115+
for _ in 0..<4 {
116+
var next: [UIView] = []
117+
for view in level {
118+
if let scrollView = view as? UIScrollView { return scrollView }
119+
next.append(contentsOf: view.subviews)
120+
}
121+
level = next
122+
}
123+
return nil
124+
}
125+
}

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
type NativeScrollEvent,
2929
type NativeSyntheticEvent,
3030
} from "react-native";
31-
import { ScrollViewMarker } from "react-native-screens";
31+
import { NativeScrollViewMarker as ScrollViewMarker } from "../../native/NativeScrollViewMarker";
3232
import { GestureDetector, useNativeGesture } from "react-native-gesture-handler";
3333
import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
3434
import { useSafeAreaInsets } from "react-native-safe-area-context";

‎apps/mobile/src/features/pull-requests/PullRequestReviewersScreen.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
type ScrollViewProps,
1818
} from "react-native";
1919
import { useSafeAreaInsets } from "react-native-safe-area-context";
20-
import { ScrollViewMarker } from "react-native-screens";
20+
import { NativeScrollViewMarker as ScrollViewMarker } from "../../native/NativeScrollViewMarker";
2121
import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText";
2222
import { EmptyState } from "../../components/ui/EmptyState";
2323
import { Button } from "../../components/ui/Button";

‎apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
View,
1717
type ScrollViewProps,
1818
} from "react-native";
19-
import { ScrollViewMarker } from "react-native-screens";
19+
import { NativeScrollViewMarker as ScrollViewMarker } from "../../native/NativeScrollViewMarker";
2020
import { useSafeAreaInsets } from "react-native-safe-area-context";
2121

2222
import { AppText as Text } from "../../components/ui/AppText";

‎apps/mobile/src/features/threads/ThreadRouteScreen.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import {
2828
projectScriptTerminalInput,
2929
resolveProjectScripts,
3030
} from "@t3tools/shared/projectScripts";
31-
import { Platform, ScrollView } from "react-native";
31+
import { Platform } from "react-native";
32+
import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
3233
import { useSafeAreaInsets } from "react-native-safe-area-context";
3334
import { useConnectionsReady } from "../../state/workspace";
3435
import { useEnvironmentShellReadiness } from "../../state/shell";

‎apps/mobile/src/features/usage/UsageLimitsPooled.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
type LimitPoolWindow,
1616
} from "@t3tools/shared/usageLimits";
1717
import { Fragment, type ReactNode, useId, useState } from "react";
18-
import { Linking, Pressable, ScrollView, View } from "react-native";
18+
import { Linking, Pressable, View } from "react-native";
19+
import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
1920
import { Defs, Path, Pattern, Rect, Svg } from "react-native-svg";
2021
import { useSafeAreaInsets } from "react-native-safe-area-context";
2122

‎apps/mobile/src/native/NativeScrollViewMarker.tsx‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { requireNativeView, requireOptionalNativeModule } from "expo";
12
import { createContext, use, type ComponentProps } from "react";
2-
import { Platform, ScrollView } from "react-native";
3+
import { Platform, ScrollView, type ViewProps } from "react-native";
4+
// oxlint-disable-next-line eslint/no-restricted-imports -- The wrapper every screen must use.
35
import { ScrollViewMarker } from "react-native-screens";
46
import { nativeHeaderScrollEdgeEffects } from "./scrollEdgeEffects";
57

@@ -9,14 +11,33 @@ const DEFAULT_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, P
911

1012
export const NativeScrollEdgeEffectsContext = createContext<ScrollEdgeEffects>(undefined);
1113

14+
function resolveScrollEdgeBleed() {
15+
try {
16+
const module = requireOptionalNativeModule<{
17+
readonly ViewPrototypes?: { readonly T3NativeControls_ScrollEdgeBleed?: unknown };
18+
}>("T3NativeControls");
19+
if (!module?.ViewPrototypes?.T3NativeControls_ScrollEdgeBleed) return null;
20+
return requireNativeView<ViewProps>("T3NativeControls", "ScrollEdgeBleed");
21+
} catch {
22+
return null;
23+
}
24+
}
25+
// Widens the scroll view under the side safe areas its column pads away (the Duo's vertical bar),
26+
// so the header's scroll-edge blur, which UIKit draws inside the scroll view, reaches the bar
27+
// while the content stays in the safe area. Every header scroll view comes through here.
28+
const ScrollEdgeBleed = Platform.OS === "ios" ? resolveScrollEdgeBleed() : null;
29+
30+
/** Registers a screen's scroll view with its header. The only way to do so: see the lint rule. */
1231
export function NativeScrollViewMarker(props: ComponentProps<typeof ScrollViewMarker>) {
1332
const effects = use(NativeScrollEdgeEffectsContext);
14-
return (
33+
const marker = (
1534
<ScrollViewMarker
1635
{...props}
36+
{...(ScrollEdgeBleed ? { style: { flex: 1 } } : {})}
1737
scrollEdgeEffects={props.scrollEdgeEffects ?? effects ?? DEFAULT_SCROLL_EDGE_EFFECTS}
1838
/>
1939
);
40+
return ScrollEdgeBleed ? <ScrollEdgeBleed style={props.style}>{marker}</ScrollEdgeBleed> : marker;
2041
}
2142

2243
export function NativeScrollView(props: ComponentProps<typeof ScrollView>) {

‎docs/internals/mobile-navigation.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ preserves behavior that is easy to break when changing native headers:
2323
- A horizontal ScrollView at its leading edge must yield to the full-screen back
2424
gesture. Upstream gives every horizontal ScrollView priority, so swiping back
2525
on a code block or table can only bounce its content.
26+
- UIKit draws the header's scroll-edge blur inside the scroll view, and workspace
27+
columns pad their content away from the iPhone Duo's vertical bar. Register a
28+
header scroll view only through
29+
[`NativeScrollViewMarker`](../../apps/mobile/src/native/NativeScrollViewMarker.tsx)
30+
or `NativeScrollView`: their native wrapper widens the scroll view under that
31+
band and insets its content by the same amount, so the blur reaches the bar and
32+
the content does not. Lint rejects `ScrollViewMarker` imported anywhere else.
2633

2734
The patch adds native header props that require code generation and a new binary.
2835
Patch rebuild guidance lives in the

‎vite.config.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ const RESTRICTED_IMPORT_PATHS = [
3939
importNames: ["CodeView"],
4040
message: "Use StyledDiffCodeView so web diff surfaces share styling and virtualized geometry.",
4141
},
42+
{
43+
name: "react-native-screens",
44+
importNames: ["ScrollViewMarker"],
45+
message:
46+
"Use NativeScrollViewMarker or NativeScrollView (src/native/NativeScrollViewMarker.tsx): they carry the header's scroll-edge blur under the Duo's vertical bar.",
47+
},
4248
];
4349

4450
const RESTRICTED_UI_VARIANT_PATTERNS = [

0 commit comments

Comments
 (0)