TypeScript
fix(mobile): every Duo header blurs under the vertical bar, from one place (#24671)
Julius Marminge90c455ff8fce
diff --git a/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift b/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swiftindex 3f9b0a6f0da..d78fa318051 100644--- a/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift+++ b/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift@@ -46,6 +46,10 @@ public final class T3NativeControlsModule: Module {Events("onMetricsChange")}+ View(T3ScrollEdgeBleedView.self) {+ ViewName("ScrollEdgeBleed")+ }+AsyncFunction("presentVideo") { (url: URL, title: String, sourceIdentifier: String, identifier: String, promise: Promise) intry self.presentVideo(url: url,diff --git a/apps/mobile/modules/t3-native-controls/ios/T3ScrollEdgeBleedView.swift b/apps/mobile/modules/t3-native-controls/ios/T3ScrollEdgeBleedView.swiftnew file mode 100644index 00000000000..188869088d4--- /dev/null+++ b/apps/mobile/modules/t3-native-controls/ios/T3ScrollEdgeBleedView.swift@@ -0,0 +1,125 @@+import ExpoModulesCore+import UIKit++/// Wraps a screen's header scroll view. Where a column pads its content away from a side safe+/// area (the iPhone Duo's vertical bar), this widens the scroll view under that band. UIKit draws+/// the header's scroll-edge effect inside the scroll view, so the blur reaches the bar like in the+/// system apps while the content stays in the safe area. Everything happens in UIKit layout, so+/// folds move the blur and the content together.+final class T3ScrollEdgeBleedView: ExpoView {+ // Fabric recycles scroll views, so everything changed here is put back before this view leaves+ // the window, which unmounting does before any recycling.+ private var scrollView: UIScrollView?+ private var container: UIView?+ private var bleed = UIEdgeInsets.zero+ /// React Native's clipping, saved while bleeding. React Native only rewrites it when the+ /// `overflow` style changes, so it stays off while bleeding.+ private var containerClipped: Bool?++ deinit {+ MainActor.assumeIsolated { detach() }+ }++ override func didMoveToWindow() {+ super.didMoveToWindow()+ if window == nil { detach() } else { setNeedsLayout() }+ }++ override func didAddSubview(_ subview: UIView) {+ super.didAddSubview(subview)+ setNeedsLayout()+ }++ override func willRemoveSubview(_ subview: UIView) {+ if let scrollView, scrollView.isDescendant(of: subview) { detach() }+ super.willRemoveSubview(subview)+ }++ override func layoutSubviews() {+ super.layoutSubviews()+ guard window != nil, let found = findScrollView(), let parent = found.superview else { return }+ if found !== scrollView {+ detach()+ scrollView = found+ container = parent+ }+ bleed = flushSafeAreaBand()+ apply()+ }++ /// The side safe areas this view sits flush against: an ancestor padded its content away from+ /// them. Only those bands are bled into, so a screen with its own margins is left alone.+ private func flushSafeAreaBand() -> UIEdgeInsets {+ var ancestor = superview+ while let view = ancestor {+ let insets = view.safeAreaInsets+ if insets.left > 0 || insets.right > 0 {+ let frame = convert(bounds, to: view)+ let left = insets.left > 0 && abs(frame.minX - insets.left) < 0.5 ? insets.left : 0+ let right = insets.right > 0 && abs(view.bounds.maxX - insets.right - frame.maxX) < 0.5+ ? insets.right : 0+ return UIEdgeInsets(top: 0, left: left, bottom: 0, right: right)+ }+ ancestor = view.superview+ }+ return .zero+ }++ /// Widening to the right leaves the content in place. Widening to the left moves it with the+ /// frame, so a left inset and offset put it back.+ private func apply() {+ guard let scrollView, let container else { return }+ // React Native sizes the scroll view's component view; the UIScrollView inside follows it by+ // autoresizing, so the widened frame survives React Native's own layout updates.+ let frame = container.bounds.inset(by: UIEdgeInsets(top: 0, left: -bleed.left, bottom: 0, right: -bleed.right))+ if scrollView.frame != frame { scrollView.frame = frame }+ if bleed == .zero {+ if let clipped = containerClipped {+ containerClipped = nil+ container.layer.masksToBounds = clipped+ }+ } else if container.layer.masksToBounds {+ // The component view clips to its own bounds, which would cut the widened scroll view back.+ // The scroll view itself still clips its content.+ containerClipped = containerClipped ?? true+ container.layer.masksToBounds = false+ }+ var inset = scrollView.contentInset+ if inset.left != bleed.left {+ inset.left = bleed.left+ scrollView.contentInset = inset+ }+ var indicators = scrollView.verticalScrollIndicatorInsets+ if indicators.right != bleed.right {+ indicators.right = bleed.right+ scrollView.verticalScrollIndicatorInsets = indicators+ }+ let x = -scrollView.adjustedContentInset.left+ if scrollView.contentOffset.x != x {+ scrollView.contentOffset = CGPoint(x: x, y: scrollView.contentOffset.y)+ }+ }++ private func detach() {+ guard scrollView != nil else { return }+ bleed = .zero+ apply()+ scrollView = nil+ container = nil+ }++ /// The scroll view sits a fixed few levels down (marker, React Native's scroll view component);+ /// never walk into a scroll view's content.+ private func findScrollView() -> UIScrollView? {+ var level: [UIView] = subviews+ for _ in 0..<4 {+ var next: [UIView] = []+ for view in level {+ if let scrollView = view as? UIScrollView { return scrollView }+ next.append(contentsOf: view.subviews)+ }+ level = next+ }+ return nil+ }+}diff --git a/apps/mobile/src/features/home/HomeScreen.tsx b/apps/mobile/src/features/home/HomeScreen.tsxindex e5d62df7c9e..7adf6f0e8a5 100644--- a/apps/mobile/src/features/home/HomeScreen.tsx+++ b/apps/mobile/src/features/home/HomeScreen.tsx@@ -27,7 +27,7 @@ import {type NativeScrollEvent,type NativeSyntheticEvent,} from "react-native";-import { ScrollViewMarker } from "react-native-screens";+import { NativeScrollViewMarker as ScrollViewMarker } from "../../native/NativeScrollViewMarker";import { GestureDetector, useNativeGesture } from "react-native-gesture-handler";import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";import { useSafeAreaInsets } from "react-native-safe-area-context";diff --git a/apps/mobile/src/features/pull-requests/PullRequestReviewersScreen.tsx b/apps/mobile/src/features/pull-requests/PullRequestReviewersScreen.tsxindex 71cbf7f9b76..1fa5cd83b87 100644--- a/apps/mobile/src/features/pull-requests/PullRequestReviewersScreen.tsx+++ b/apps/mobile/src/features/pull-requests/PullRequestReviewersScreen.tsx@@ -17,7 +17,7 @@ import {type ScrollViewProps,} from "react-native";import { useSafeAreaInsets } from "react-native-safe-area-context";-import { ScrollViewMarker } from "react-native-screens";+import { NativeScrollViewMarker as ScrollViewMarker } from "../../native/NativeScrollViewMarker";import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText";import { EmptyState } from "../../components/ui/EmptyState";import { Button } from "../../components/ui/Button";diff --git a/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx b/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsxindex e722f052b26..6c48ceb446e 100644--- a/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx+++ b/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx@@ -16,7 +16,7 @@ import {View,type ScrollViewProps,} from "react-native";-import { ScrollViewMarker } from "react-native-screens";+import { NativeScrollViewMarker as ScrollViewMarker } from "../../native/NativeScrollViewMarker";import { useSafeAreaInsets } from "react-native-safe-area-context";import { AppText as Text } from "../../components/ui/AppText";diff --git a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx b/apps/mobile/src/features/threads/ThreadRouteScreen.tsxindex d120c9a544c..851fe0fb7ce 100644--- a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx+++ b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx@@ -28,7 +28,8 @@ import {projectScriptTerminalInput,resolveProjectScripts,} from "@t3tools/shared/projectScripts";-import { Platform, ScrollView } from "react-native";+import { Platform } from "react-native";+import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";import { useSafeAreaInsets } from "react-native-safe-area-context";import { useConnectionsReady } from "../../state/workspace";import { useEnvironmentShellReadiness } from "../../state/shell";diff --git a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx b/apps/mobile/src/features/usage/UsageLimitsPooled.tsxindex fcd927b8d32..1eec514d330 100644--- a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx+++ b/apps/mobile/src/features/usage/UsageLimitsPooled.tsx@@ -15,7 +15,8 @@ import {type LimitPoolWindow,} from "@t3tools/shared/usageLimits";import { Fragment, type ReactNode, useId, useState } from "react";-import { Linking, Pressable, ScrollView, View } from "react-native";+import { Linking, Pressable, View } from "react-native";+import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";import { Defs, Path, Pattern, Rect, Svg } from "react-native-svg";import { useSafeAreaInsets } from "react-native-safe-area-context";diff --git a/apps/mobile/src/native/NativeScrollViewMarker.tsx b/apps/mobile/src/native/NativeScrollViewMarker.tsxindex 80b28ef7b4d..f1bd81feaf8 100644--- a/apps/mobile/src/native/NativeScrollViewMarker.tsx+++ b/apps/mobile/src/native/NativeScrollViewMarker.tsx@@ -1,5 +1,7 @@+import { requireNativeView, requireOptionalNativeModule } from "expo";import { createContext, use, type ComponentProps } from "react";-import { Platform, ScrollView } from "react-native";+import { Platform, ScrollView, type ViewProps } from "react-native";+// oxlint-disable-next-line eslint/no-restricted-imports -- The wrapper every screen must use.import { ScrollViewMarker } from "react-native-screens";import { nativeHeaderScrollEdgeEffects } from "./scrollEdgeEffects";@@ -9,14 +11,33 @@ const DEFAULT_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Pexport const NativeScrollEdgeEffectsContext = createContext<ScrollEdgeEffects>(undefined);+function resolveScrollEdgeBleed() {+ try {+ const module = requireOptionalNativeModule<{+ readonly ViewPrototypes?: { readonly T3NativeControls_ScrollEdgeBleed?: unknown };+ }>("T3NativeControls");+ if (!module?.ViewPrototypes?.T3NativeControls_ScrollEdgeBleed) return null;+ return requireNativeView<ViewProps>("T3NativeControls", "ScrollEdgeBleed");+ } catch {+ return null;+ }+}+// Widens the scroll view under the side safe areas its column pads away (the Duo's vertical bar),+// so the header's scroll-edge blur, which UIKit draws inside the scroll view, reaches the bar+// while the content stays in the safe area. Every header scroll view comes through here.+const ScrollEdgeBleed = Platform.OS === "ios" ? resolveScrollEdgeBleed() : null;++/** Registers a screen's scroll view with its header. The only way to do so: see the lint rule. */export function NativeScrollViewMarker(props: ComponentProps<typeof ScrollViewMarker>) {const effects = use(NativeScrollEdgeEffectsContext);- return (+ const marker = (<ScrollViewMarker{...props}+ {...(ScrollEdgeBleed ? { style: { flex: 1 } } : {})}scrollEdgeEffects={props.scrollEdgeEffects ?? effects ?? DEFAULT_SCROLL_EDGE_EFFECTS}/>);+ return ScrollEdgeBleed ? <ScrollEdgeBleed style={props.style}>{marker}</ScrollEdgeBleed> : marker;}export function NativeScrollView(props: ComponentProps<typeof ScrollView>) {diff --git a/docs/internals/mobile-navigation.md b/docs/internals/mobile-navigation.mdindex 94bd550d142..0718effe7b4 100644--- a/docs/internals/mobile-navigation.md+++ b/docs/internals/mobile-navigation.md@@ -23,6 +23,13 @@ preserves behavior that is easy to break when changing native headers:- A horizontal ScrollView at its leading edge must yield to the full-screen backgesture. Upstream gives every horizontal ScrollView priority, so swiping backon a code block or table can only bounce its content.+- UIKit draws the header's scroll-edge blur inside the scroll view, and workspace+ columns pad their content away from the iPhone Duo's vertical bar. Register a+ header scroll view only through+ [`NativeScrollViewMarker`](../../apps/mobile/src/native/NativeScrollViewMarker.tsx)+ or `NativeScrollView`: their native wrapper widens the scroll view under that+ band and insets its content by the same amount, so the blur reaches the bar and+ the content does not. Lint rejects `ScrollViewMarker` imported anywhere else.The patch adds native header props that require code generation and a new binary.Patch rebuild guidance lives in thediff --git a/vite.config.ts b/vite.config.tsindex 25fbe4e6f9a..b8ee4011ca6 100644--- a/vite.config.ts+++ b/vite.config.ts@@ -39,6 +39,12 @@ const RESTRICTED_IMPORT_PATHS = [importNames: ["CodeView"],message: "Use StyledDiffCodeView so web diff surfaces share styling and virtualized geometry.",},+ {+ name: "react-native-screens",+ importNames: ["ScrollViewMarker"],+ message:+ "Use NativeScrollViewMarker or NativeScrollView (src/native/NativeScrollViewMarker.tsx): they carry the header's scroll-edge blur under the Duo's vertical bar.",+ },];const RESTRICTED_UI_VARIANT_PATTERNS = [