Skip to content

Commit d0b9e9d

Browse files
fix(mobile): the Duo header blur reaches a vertical bar on the left too (#24807)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 5b35402 commit d0b9e9d

2 files changed

Lines changed: 55 additions & 34 deletions

File tree

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

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ import ExpoModulesCore
22
import UIKit
33

44
/// Wraps a screen's header scroll view. Where a column pads its content away from the iPhone Duo's
5-
/// vertical bar, this widens the scroll view under the bar. 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.
5+
/// vertical bar, this widens the scroll view under the bar, like the system apps' lists. UIKit
6+
/// draws the header's scroll-edge effect inside the scroll view, so the blur reaches the bar while
7+
/// the content stays in the safe area. Everything happens in UIKit layout, so folds move the blur
8+
/// and the content together.
99
final class T3ScrollEdgeBleedView: ExpoView {
1010
// Fabric recycles scroll views, so everything changed here is put back before this view leaves
1111
// the window, which unmounting does before any recycling.
1212
private var scrollView: UIScrollView?
1313
private var container: UIView?
14-
private var bleed: CGFloat = 0
14+
/// React Native's content view, which every row lives in.
15+
private var content: UIView?
16+
private var bleed = UIEdgeInsets.zero
1517
/// Whether the scroll view currently carries this view's changes.
1618
private var applied = false
1719
/// React Native's clipping, saved while bleeding. React Native only rewrites it when the
@@ -55,55 +57,72 @@ final class T3ScrollEdgeBleedView: ExpoView {
5557
detach()
5658
scrollView = found
5759
container = parent
60+
// React Native adds one plain UIView to its scroll view and mounts every child into it.
61+
content = found.subviews.first { type(of: $0) == UIView.self }
5862
}
5963
bleed = verticalBarBleed()
64+
// Without the content view to shift back, bleeding left would move the rows under the bar.
65+
if content == nil { bleed.left = 0 }
6066
apply()
6167
}
6268

63-
/// How far the vertical bar's safe area reaches past this view's right edge, when this view sits
64-
/// flush against the padding its column added for it. Nothing else is bled into: not a sidebar
65-
/// column overlapping this one, not a notch, and not a bar on the left, where widening would
66-
/// move the content and need a horizontal offset React Native keeps rewriting.
67-
private func verticalBarBleed() -> CGFloat {
68-
guard verticalBarIsOnTheRight() else { return 0 }
69+
/// How far the vertical bar's safe area reaches past this view's edge, when this view sits flush
70+
/// against the padding its column added for it. Nothing else is bled into: not a sidebar column
71+
/// overlapping this one, and not a notch.
72+
private func verticalBarBleed() -> UIEdgeInsets {
73+
guard let side = verticalBarSide() else { return .zero }
6974
var ancestor = superview
7075
while let view = ancestor {
71-
let inset = view.safeAreaInsets.right
76+
let inset = side == .left ? view.safeAreaInsets.left : view.safeAreaInsets.right
7277
if inset > 0 {
7378
let frame = convert(bounds, to: view)
74-
return abs(view.bounds.maxX - inset - frame.maxX) < 0.5 ? inset : 0
79+
let flush = side == .left
80+
? abs(frame.minX - (view.bounds.minX + inset)) < 0.5
81+
: abs(view.bounds.maxX - inset - frame.maxX) < 0.5
82+
guard flush else { return .zero }
83+
return side == .left
84+
? UIEdgeInsets(top: 0, left: inset, bottom: 0, right: 0)
85+
: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: inset)
7586
}
7687
ancestor = view.superview
7788
}
78-
return 0
89+
return .zero
7990
}
8091

81-
private func verticalBarIsOnTheRight() -> Bool {
92+
private enum Side { case left, right }
93+
94+
private func verticalBarSide() -> Side? {
8295
// The vertical-bar API ships in the iOS 27.1 SDK (UIKit 9127.0.85); see T3LayoutMetricsView.
8396
#if canImport(UIKit, _version: 9127.0.85)
8497
if #available(iOS 27.1, *) {
8598
let rtl = effectiveUserInterfaceLayoutDirection == .rightToLeft
8699
switch traitCollection.verticalBarEdge {
87-
case .leading: return rtl
88-
case .trailing: return !rtl
89-
default: return false
100+
case .leading: return rtl ? .right : .left
101+
case .trailing: return rtl ? .left : .right
102+
default: return nil
90103
}
91104
}
92105
#endif
93-
return false
106+
return nil
94107
}
95108

96-
/// Widening to the right leaves the content where React Native laid it out, so only the frame,
97-
/// the container's clipping and the scroll indicator change; contentInset and contentOffset are
98-
/// never touched. Nothing at all is written unless this view is bleeding or undoing its bleed.
109+
/// Widening to the left would move the rows with it. Instead of a horizontal content offset,
110+
/// which React Native rewrites on its own layout passes, the content view's bounds origin shifts
111+
/// them back: React Native only ever sets that view's frame, which leaves its bounds origin.
112+
/// Nothing at all is written unless this view is bleeding or undoing its bleed.
99113
private func apply() {
100114
guard let scrollView, let container else { return }
101-
guard bleed > 0 || applied else { return }
115+
let bleeding = bleed != .zero
116+
guard bleeding || applied else { return }
102117
// React Native sizes the scroll view's component view; the UIScrollView inside follows it by
103118
// autoresizing, so the widened frame survives React Native's own layout updates.
104-
let frame = container.bounds.inset(by: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: -bleed))
119+
let frame = container.bounds.inset(
120+
by: UIEdgeInsets(top: 0, left: -bleed.left, bottom: 0, right: -bleed.right))
105121
if scrollView.frame != frame { scrollView.frame = frame }
106-
if bleed == 0 {
122+
if let content, content.bounds.origin.x != -bleed.left {
123+
content.bounds.origin.x = -bleed.left
124+
}
125+
if !bleeding {
107126
if let clipped = containerClipped {
108127
containerClipped = nil
109128
container.layer.masksToBounds = clipped
@@ -115,19 +134,20 @@ final class T3ScrollEdgeBleedView: ExpoView {
115134
container.layer.masksToBounds = false
116135
}
117136
var indicators = scrollView.verticalScrollIndicatorInsets
118-
if indicators.right != bleed {
119-
indicators.right = bleed
137+
if indicators.right != bleed.right {
138+
indicators.right = bleed.right
120139
scrollView.verticalScrollIndicatorInsets = indicators
121140
}
122-
applied = bleed > 0
141+
applied = bleeding
123142
}
124143

125144
private func detach() {
126145
guard scrollView != nil else { return }
127-
bleed = 0
146+
bleed = .zero
128147
apply()
129148
scrollView = nil
130149
container = nil
150+
content = nil
131151
}
132152

133153
/// The scroll view sits a fixed few levels down (marker, React Native's scroll view component);

‎docs/internals/mobile-navigation.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ preserves behavior that is easy to break when changing native headers:
5353
columns pad their content away from the iPhone Duo's vertical bar. Register a
5454
header scroll view only through
5555
[`NativeScrollViewMarker`](../../apps/mobile/src/native/NativeScrollViewMarker.tsx)
56-
or `NativeScrollView`: their native wrapper widens the scroll view to the right
57-
under that bar, so the blur reaches it while the content keeps its React Native
58-
frame. It never bleeds left: that would need a horizontal content offset, which
59-
React Native rewrites on its own layout passes. Lint rejects `ScrollViewMarker`
60-
imported anywhere else.
56+
or `NativeScrollView`: their native wrapper widens the scroll view under that
57+
bar, so the blur reaches it while the content stays in the safe area. On the
58+
left it shifts React Native's content view back through its bounds origin,
59+
never with a content offset: React Native rewrites offsets on its own layout
60+
passes, which left threads shifted under the bar. Lint rejects
61+
`ScrollViewMarker` imported anywhere else.
6162

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

0 commit comments

Comments
 (0)