Skip to content

Commit a0e0f8a

Browse files
fix(mobile): Duo threads no longer open shifted left (#24732)
1 parent b808f7f commit a0e0f8a

2 files changed

Lines changed: 57 additions & 33 deletions

File tree

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

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import ExpoModulesCore
22
import UIKit
33

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
4+
/// 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
66
/// the header's scroll-edge effect inside the scroll view, so the blur reaches the bar like in the
77
/// system apps while the content stays in the safe area. Everything happens in UIKit layout, so
88
/// folds move the blur and the content together.
@@ -11,11 +11,24 @@ final class T3ScrollEdgeBleedView: ExpoView {
1111
// the window, which unmounting does before any recycling.
1212
private var scrollView: UIScrollView?
1313
private var container: UIView?
14-
private var bleed = UIEdgeInsets.zero
14+
private var bleed: CGFloat = 0
15+
/// Whether the scroll view currently carries this view's changes.
16+
private var applied = false
1517
/// React Native's clipping, saved while bleeding. React Native only rewrites it when the
1618
/// `overflow` style changes, so it stays off while bleeding.
1719
private var containerClipped: Bool?
1820

21+
required init(appContext: AppContext? = nil) {
22+
super.init(appContext: appContext)
23+
#if canImport(UIKit, _version: 9127.0.85)
24+
if #available(iOS 27.1, *) {
25+
registerForTraitChanges(UITraitCollection.systemTraitsAffectingVerticalBarEdge) { (view: T3ScrollEdgeBleedView, _: UITraitCollection) in
26+
view.setNeedsLayout()
27+
}
28+
}
29+
#endif
30+
}
31+
1932
deinit {
2033
MainActor.assumeIsolated { detach() }
2134
}
@@ -43,37 +56,54 @@ final class T3ScrollEdgeBleedView: ExpoView {
4356
scrollView = found
4457
container = parent
4558
}
46-
bleed = flushSafeAreaBand()
59+
bleed = verticalBarBleed()
4760
apply()
4861
}
4962

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 {
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 }
5369
var ancestor = superview
5470
while let view = ancestor {
55-
let insets = view.safeAreaInsets
56-
if insets.left > 0 || insets.right > 0 {
71+
let inset = view.safeAreaInsets.right
72+
if inset > 0 {
5773
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)
74+
return abs(view.bounds.maxX - inset - frame.maxX) < 0.5 ? inset : 0
6275
}
6376
ancestor = view.superview
6477
}
65-
return .zero
78+
return 0
79+
}
80+
81+
private func verticalBarIsOnTheRight() -> Bool {
82+
// The vertical-bar API ships in the iOS 27.1 SDK (UIKit 9127.0.85); see T3LayoutMetricsView.
83+
#if canImport(UIKit, _version: 9127.0.85)
84+
if #available(iOS 27.1, *) {
85+
let rtl = effectiveUserInterfaceLayoutDirection == .rightToLeft
86+
switch traitCollection.verticalBarEdge {
87+
case .leading: return rtl
88+
case .trailing: return !rtl
89+
default: return false
90+
}
91+
}
92+
#endif
93+
return false
6694
}
6795

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.
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.
7099
private func apply() {
71100
guard let scrollView, let container else { return }
101+
guard bleed > 0 || applied else { return }
72102
// React Native sizes the scroll view's component view; the UIScrollView inside follows it by
73103
// 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))
104+
let frame = container.bounds.inset(by: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: -bleed))
75105
if scrollView.frame != frame { scrollView.frame = frame }
76-
if bleed == .zero {
106+
if bleed == 0 {
77107
if let clipped = containerClipped {
78108
containerClipped = nil
79109
container.layer.masksToBounds = clipped
@@ -84,25 +114,17 @@ final class T3ScrollEdgeBleedView: ExpoView {
84114
containerClipped = containerClipped ?? true
85115
container.layer.masksToBounds = false
86116
}
87-
var inset = scrollView.contentInset
88-
if inset.left != bleed.left {
89-
inset.left = bleed.left
90-
scrollView.contentInset = inset
91-
}
92117
var indicators = scrollView.verticalScrollIndicatorInsets
93-
if indicators.right != bleed.right {
94-
indicators.right = bleed.right
118+
if indicators.right != bleed {
119+
indicators.right = bleed
95120
scrollView.verticalScrollIndicatorInsets = indicators
96121
}
97-
let x = -scrollView.adjustedContentInset.left
98-
if scrollView.contentOffset.x != x {
99-
scrollView.contentOffset = CGPoint(x: x, y: scrollView.contentOffset.y)
100-
}
122+
applied = bleed > 0
101123
}
102124

103125
private func detach() {
104126
guard scrollView != nil else { return }
105-
bleed = .zero
127+
bleed = 0
106128
apply()
107129
scrollView = nil
108130
container = nil

‎docs/internals/mobile-navigation.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ preserves behavior that is easy to break when changing native headers:
2727
columns pad their content away from the iPhone Duo's vertical bar. Register a
2828
header scroll view only through
2929
[`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.
30+
or `NativeScrollView`: their native wrapper widens the scroll view to the right
31+
under that bar, so the blur reaches it while the content keeps its React Native
32+
frame. It never bleeds left: that would need a horizontal content offset, which
33+
React Native rewrites on its own layout passes. Lint rejects `ScrollViewMarker`
34+
imported anywhere else.
3335

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

0 commit comments

Comments
 (0)