@devries-cameron20 / t3code-1 / commits / 7510e5e43c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): Android dialogs raised before or during activity replacement now show (#25229)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 25, 2026 at 21:02 UTC 7510e5e43c6cb40d454530c9aaa9a8fbb43ab1bf
13 files changed +244 -169
apps/mobile/src/components/ui/AndroidAnchoredMenu.tsx
+41 -42
@@ -1,11 +1,12 @@
1 import type { MenuAction, MenuComponentProps } from "@react-native-menu/menu";
2 import type { ReactNode } from "react";
3 -import { use, useCallback, useEffect, useRef, useState } from "react";
3 +import { use, useRef, useState } from "react";
4 import type { StyleProp, ViewInstance, ViewStyle } from "react-native";
5 -import { BackHandler, Pressable, ScrollView, View } from "react-native";
5 +import { Pressable, ScrollView, View } from "react-native";
6 import { useKeyboardState } from "react-native-keyboard-controller";
7 import Animated, { FadeIn } from "react-native-reanimated";
8
9 +import { useHardwareBack } from "../../lib/backHandler";
10 import { deriveMenuHorizontalPlacement } from "../../lib/menu-placement";
11 import { WindowHingeContext } from "../../native/window-hinge-context";
12 import { OverlayPortal } from "./OverlayPortal";
@@ -47,46 +48,43 @@ export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
48 const [rootHeight, setRootHeight] = useState<number | null>(null);
49 const [overlay, setOverlay] = useState<OverlayFrame | null>(null);
50 const windowHinge = use(WindowHingeContext);
50 - const anchorRef = useRef<ViewInstance>(null);
51 + // State, not a ref: `open` reaches render-prop children, and the compiler
52 + // bails out of the whole component when a ref might be read during render.
53 + const [anchorNode, setAnchorNode] = useState<ViewInstance | null>(null);
54 const overlayRef = useRef<ViewInstance>(null);
55
56 const keyboardVisible = useKeyboardState((state) => state.isVisible);
57 const keyboardHeight = useKeyboardState((state) => state.height);
55 - const close = useCallback(() => {
58 + const close = () => {
59 setAnchor(null);
60 setPath([]);
61 setOverlay(null);
62 setRootHeight(null);
60 - }, []);
63 + };
64
62 - const open = useCallback(() => {
63 - anchorRef.current?.measureInWindow((x, y, width, height) => {
65 + const open = () => {
66 + anchorNode?.measureInWindow((x, y, width, height) => {
67 setAnchor({ x, y, width, height, keyboardWasVisible: keyboardVisible });
68 });
66 - }, [keyboardVisible]);
69 + };
70
68 - const measureOverlay = useCallback(() => {
71 + const measureOverlay = () => {
72 overlayRef.current?.measureInWindow((x, y, width, height) => {
73 setOverlay({ x, y, width, height });
74 setRootHeight(height);
75 });
73 - }, []);
76 + };
77
75 - const submenuDepth = path.length;
76 - useEffect(() => {
77 - if (anchor === null || !anchor.keyboardWasVisible) {
78 - return;
78 + // Only the in-window (keyboard) presentation needs this; the native popup
79 + // handles back itself.
80 + useHardwareBack(anchor?.keyboardWasVisible === true, () => {
81 + if (path.length > 0) {
82 + setPath((current) => current.slice(0, -1));
83 + } else {
84 + close();
85 }
80 - const subscription = BackHandler.addEventListener("hardwareBackPress", () => {
81 - if (submenuDepth > 0) {
82 - setPath((current) => current.slice(0, -1));
83 - } else {
84 - close();
85 - }
86 - return true;
87 - });
88 - return () => subscription.remove();
89 - }, [anchor, close, submenuDepth]);
86 + return true;
87 + });
88
89 const parent = path[path.length - 1] ?? null;
90 const levelActions = (parent?.subactions ?? props.actions).filter(
@@ -125,32 +123,33 @@ export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
123 const maxHeight = Math.min(opensDown ? spaceBelow : spaceAbove, 480);
124 const placeable = local !== null && rootHeight !== null;
125
128 - const { onPressAction } = props;
129 - const onPressItem = useCallback(
130 - (action: MenuAction) => {
131 - if ((action.subactions?.length ?? 0) > 0) {
132 - setPath((current) => [...current, action]);
133 - return;
134 - }
135 - close();
136 - if (action.id !== undefined) {
137 - onPressAction?.({
138 - nativeEvent: { event: action.id },
139 - } as Parameters<NonNullable<MenuComponentProps["onPressAction"]>>[0]);
140 - }
141 - },
142 - [close, onPressAction],
143 - );
126 + const onPressItem = (action: MenuAction) => {
127 + if ((action.subactions?.length ?? 0) > 0) {
128 + setPath((current) => [...current, action]);
129 + return;
130 + }
131 + close();
132 + if (action.id !== undefined) {
133 + props.onPressAction?.({
134 + nativeEvent: { event: action.id },
135 + } as Parameters<NonNullable<MenuComponentProps["onPressAction"]>>[0]);
136 + }
137 + };
138
139 return (
140 <>
141 {typeof props.children === "function" ? (
148 - <View ref={anchorRef} collapsable={false} className={props.className} style={props.style}>
142 + <View
143 + ref={setAnchorNode}
144 + collapsable={false}
145 + className={props.className}
146 + style={props.style}
147 + >
148 {props.children(open)}
149 </View>
150 ) : (
151 <Pressable
153 - ref={anchorRef}
152 + ref={setAnchorNode}
153 accessibilityRole="button"
154 className={props.className}
155 collapsable={false}
apps/mobile/src/components/ui/Dialog.android.test.tsx
+40 -3
@@ -2,11 +2,16 @@ import { act, type ReactNode } from "react";
2 import { createRoot, type Root } from "react-dom/client";
3 import { afterEach, expect, it, vi } from "vite-plus/test";
4
5 +// Every click handler a button was rendered with, so a test can deliver a
6 +// native event that was dispatched against an older render.
7 +const renderedClicks = vi.hoisted(() => [] as Array<() => void>);
8 +
9 vi.mock("@expo/ui/jetpack-compose", () => {
10 const Slot = (props: { readonly children?: ReactNode }) => <div>{props.children}</div>;
7 - const Button = (props: { readonly children?: ReactNode; readonly onClick?: () => void }) => (
8 - <button onClick={props.onClick}>{props.children}</button>
9 - );
11 + const Button = (props: { readonly children?: ReactNode; readonly onClick?: () => void }) => {
12 + if (props.onClick) renderedClicks.push(props.onClick);
13 + return <button onClick={props.onClick}>{props.children}</button>;
14 + };
15 return {
16 AlertDialog: Object.assign(Slot, {
17 Title: Slot,
@@ -51,6 +56,7 @@ function mountHost() {
56
57 afterEach(() => {
58 for (const root of roots.splice(0)) act(() => root.unmount());
59 + renderedClicks.length = 0;
60 document.body.innerHTML = "";
61 });
62
@@ -65,3 +71,34 @@ it("keeps presenting dialogs after an older root's Host unmounts", () => {
71
72 expect(current.container.textContent).toContain("Saved");
73 });
74 +
75 +it("presents a dialog requested before any Host mounted", () => {
76 + Dialog.alert("Could not import shared content", undefined, [{ text: "Dismiss" }]);
77 +
78 + const { container } = mountHost();
79 +
80 + expect(container.textContent).toContain("Could not import shared content");
81 +});
82 +
83 +it("keeps a dialog raised while the activity is replaced", () => {
84 + const previous = mountHost();
85 + act(() => Dialog.alert("Shared content imported", undefined, [{ text: "OK" }]));
86 + const current = mountHost();
87 + roots.splice(roots.indexOf(previous.root), 1);
88 + act(() => previous.root.unmount());
89 +
90 + expect(current.container.textContent).toContain("Shared content imported");
91 +});
92 +
93 +it("ignores a late action from a dialog that a newer one replaced", () => {
94 + const { container } = mountHost();
95 + const olderAction = vi.fn();
96 + act(() => Dialog.alert("Older", undefined, [{ text: "OK", onPress: olderAction }]));
97 + const olderClick = renderedClicks.at(-1)!;
98 + act(() => Dialog.alert("Newer", undefined, [{ text: "OK" }]));
99 +
100 + act(() => olderClick());
101 +
102 + expect(olderAction).toHaveBeenCalledOnce();
103 + expect(container.textContent).toContain("Newer");
104 +});
apps/mobile/src/components/ui/Dialog.android.tsx
+54 -42
@@ -14,7 +14,7 @@ import {
14 import { useAppearancePreferences } from "../../features/settings/appearance/AppearancePreferencesProvider";
15 import { useScaledTextRole } from "../../features/settings/appearance/useScaledTextRole";
16
17 -import { useCallback, useEffect, useRef, useState } from "react";
17 +import { useSyncExternalStore } from "react";
18 import { themeColorWithContrast } from "../../lib/mobileTheme";
19 import type { Alert, AlertButton } from "react-native";
20 import type { ConfirmDialogRequest, TextInputDialogRequest } from "./Dialog.types";
@@ -33,63 +33,78 @@ type DialogRequest =
33 | { readonly kind: "confirm"; readonly request: ConfirmDialogRequest }
34 | { readonly kind: "text-input"; readonly request: TextInputDialogRequest };
35
36 -let presentRequest: ((request: DialogRequest) => void) | null = null;
36 +type PresentedDialog = DialogRequest & { readonly id: number };
37 +
38 +// App services raise dialogs before the root mounts, so the request lives in
39 +// the module and the Host renders whatever is current. One dialog shows at a
40 +// time: a new request replaces the presented one.
41 +let presented: PresentedDialog | null = null;
42 +let nextPresentationId = 0;
43 +const listeners = new Set<() => void>();
44 +
45 +function setPresented(next: PresentedDialog | null) {
46 + presented = next;
47 + for (const listener of listeners) listener();
48 +}
49 +
50 +function submitRequest(dialog: DialogRequest) {
51 + setPresented({ ...dialog, id: ++nextPresentationId });
52 +}
53 +
54 +/** Closes the dialog only if it is still the one the action came from. */
55 +function dismiss(id: number) {
56 + if (presented?.id === id) setPresented(null);
57 +}
58 +
59 +function subscribe(listener: () => void) {
60 + listeners.add(listener);
61 + return () => {
62 + listeners.delete(listener);
63 + };
64 +}
65 +
66 +function getPresented() {
67 + return presented;
68 +}
69
70 export function alert(...[title, message, buttons, options]: Parameters<typeof Alert.alert>): void {
71 const actions = buttons?.length ? buttons.slice(0, 3) : [{ text: "OK" }];
72 const normalized = actions.map((action, index) =>
73 index === actions.length - 1 ? { ...action, text: action.text || "OK" } : action,
74 );
43 - presentRequest?.({
75 + submitRequest({
76 kind: "alert",
77 request: { title, message, buttons: normalized, options },
78 });
79 }
80
81 export function confirm(request: ConfirmDialogRequest): void {
50 - presentRequest?.({ kind: "confirm", request });
82 + submitRequest({ kind: "confirm", request });
83 }
84
85 export function prompt(request: TextInputDialogRequest): void {
54 - presentRequest?.({ kind: "text-input", request });
86 + submitRequest({ kind: "text-input", request });
87 }
88
89 export function Host() {
58 - const [presented, setPresented] = useState<(DialogRequest & { readonly id: number }) | null>(
59 - null,
60 - );
61 - const [inputValue, setInputValue] = useState("");
62 - const nextPresentationId = useRef(0);
63 - useEffect(() => {
64 - const present = (request: DialogRequest) => {
65 - setInputValue(request.kind === "text-input" ? request.request.initialValue : "");
66 - setPresented({ ...request, id: ++nextPresentationId.current });
67 - };
68 - presentRequest = present;
69 - return () => {
70 - // When Android replaces the activity, the new root's Host registers before the old root
71 - // unmounts. Clearing unconditionally would leave the live Host without dialogs.
72 - if (presentRequest === present) presentRequest = null;
73 - };
74 - }, []);
90 + const presented = useSyncExternalStore(subscribe, getPresented, getPresented);
91
76 - const handleCancel = useCallback(() => {
77 - setPresented(null);
78 - if (presented?.kind === "alert") presented.request.options?.onDismiss?.();
79 - else presented?.request.onCancel?.();
80 - }, [presented]);
92 + const handleCancel = () => {
93 + if (!presented) return;
94 + dismiss(presented.id);
95 + if (presented.kind === "alert") presented.request.options?.onDismiss?.();
96 + else presented.request.onCancel?.();
97 + };
98
82 - const handleConfirm = useCallback(
83 - (nativeInputValue?: string) => {
84 - setPresented(null);
85 - if (presented?.kind === "confirm") {
86 - presented.request.onConfirm();
87 - } else if (presented?.kind === "text-input") {
88 - presented.request.onConfirm(nativeInputValue ?? inputValue);
89 - }
90 - },
91 - [inputValue, presented],
92 - );
99 + const handleConfirm = (nativeInputValue?: string) => {
100 + if (!presented) return;
101 + dismiss(presented.id);
102 + if (presented.kind === "confirm") {
103 + presented.request.onConfirm();
104 + } else if (presented.kind === "text-input") {
105 + presented.request.onConfirm(nativeInputValue ?? presented.request.initialValue);
106 + }
107 + };
108
109 if (presented?.kind === "alert") {
110 return (
@@ -103,7 +118,7 @@ export function Host() {
118 alertActions={presented.request.buttons ?? [{ text: "OK" }]}
119 dismissable={presented.request.options?.cancelable ?? false}
120 onAlertAction={(action) => {
106 - setPresented(null);
121 + dismiss(presented.id);
122 action.onPress?.();
123 }}
124 onCancel={handleCancel}
@@ -120,7 +135,6 @@ export function Host() {
135 presented.kind === "text-input" ? presented.request.initialValue : undefined
136 }
137 inputPlaceholder={presented.kind === "text-input" ? presented.request.placeholder : undefined}
123 - onInputChange={setInputValue}
138 onCancel={handleCancel}
139 onConfirm={handleConfirm}
140 />
@@ -212,7 +226,6 @@ function DialogPresentation(props: DialogPresentationProps) {
226 singleLine
227 value={inputState}
228 selection={inputSelection}
215 - onValueChange={props.onInputChange}
229 textStyle={inputTypography}
230 keyboardOptions={{ imeAction: "done" }}
231 keyboardActions={{
@@ -267,7 +280,6 @@ interface DialogPresentationProps {
280 >;
281 readonly inputInitialValue?: string;
282 readonly inputPlaceholder?: string;
270 - readonly onInputChange?: (value: string) => void;
283 readonly onCancel: () => void;
284 readonly onConfirm: (inputValue?: string) => void;
285 }
apps/mobile/src/components/ui/OverlayPortal.tsx
+23 -14
@@ -1,9 +1,8 @@
1 -import { type ReactNode, useEffect, useState } from "react";
1 +import { type ReactNode, useEffect, useState, useSyncExternalStore } from "react";
2 import { View } from "react-native";
3
4 // RN Modals move native window focus and close the keyboard. Keep composer menus in-window.
5 type Entries = ReadonlyMap<number, ReactNode>;
6 -type Listener = (entries: Entries) => void;
6
7 let nextKey = 0;
8
@@ -11,24 +10,41 @@ function allocateKey() {
10 return nextKey++;
11 }
12 const entries = new Map<number, ReactNode>();
14 -const listeners = new Set<Listener>();
13 +const listeners = new Set<() => void>();
14 +let snapshot: Entries = new Map();
15
16 function emit() {
17 - const snapshot = new Map(entries);
17 + snapshot = new Map(entries);
18 for (const listener of listeners) {
19 - listener(snapshot);
19 + listener();
20 }
21 }
22
23 +function subscribe(listener: () => void) {
24 + listeners.add(listener);
25 + return () => {
26 + listeners.delete(listener);
27 + };
28 +}
29 +
30 +function getSnapshot() {
31 + return snapshot;
32 +}
33 +
34 export function OverlayPortal(props: { readonly children: ReactNode }) {
35 const [key] = useState(allocateKey);
36
26 - // Re-project every render so open menus reflect content and theme changes.
37 + // RN has no createPortal, so projecting into the out-of-tree host has to
38 + // happen after commit. No dependency array: re-project after every render so
39 + // the host always shows the current content (menus re-render while open —
40 + // drill-in, theme).
41 useEffect(() => {
42 entries.set(key, props.children);
43 emit();
44 });
45
46 + // Removal is unmount-only: deleting on every re-projection would move the
47 + // entry to the end of the map and restack it above overlays opened later.
48 useEffect(
49 () => () => {
50 entries.delete(key);
@@ -41,14 +57,7 @@ export function OverlayPortal(props: { readonly children: ReactNode }) {
57 }
58
59 export function OverlayPortalHost() {
44 - const [current, setCurrent] = useState<Entries>(() => new Map());
45 -
46 - useEffect(() => {
47 - listeners.add(setCurrent);
48 - return () => {
49 - listeners.delete(setCurrent);
50 - };
51 - }, []);
60 + const current = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
61
62 if (current.size === 0) {
63 return null;
apps/mobile/src/components/ui/SliderRow.android.tsx
+6 -9
@@ -1,7 +1,7 @@
1 import { Slider } from "@expo/ui/jetpack-compose";
2 import { fillMaxWidth } from "@expo/ui/jetpack-compose/modifiers";
3 import * as Haptics from "expo-haptics";
4 -import { useEffect, useRef } from "react";
4 +import { useRef } from "react";
5 import { View } from "react-native";
6
7 import { AppText as Text } from "./AppText";
@@ -12,11 +12,8 @@ import type { SliderRowProps } from "./SliderRow.types";
12
13 export function SliderRow(props: SliderRowProps) {
14 const { colors } = useControlTheme();
15 - const draft = useRef(props.value);
16 - const dragging = useRef(false);
17 - useEffect(() => {
18 - if (!dragging.current) draft.current = props.value;
19 - }, [props.value]);
15 + // The value of the drag in progress; null between drags.
16 + const draft = useRef<number | null>(null);
17 const commit = (value: number) => {
18 if (props.disabled) return;
19 const next = Math.min(
@@ -66,12 +63,12 @@ export function SliderRow(props: SliderRowProps) {
63 inactiveTrackColor: colors["--color-secondary"],
64 }}
65 onValueChange={(value) => {
69 - dragging.current = true;
66 draft.current = value;
67 }}
68 onValueChangeFinished={() => {
73 - dragging.current = false;
74 - commit(draft.current);
69 + const value = draft.current;
70 + draft.current = null;
71 + if (value !== null) commit(value);
72 }}
73 />
74 </NativeThemeHost>
apps/mobile/src/components/ui/SliderRow.tsx
+8 -8
@@ -6,7 +6,7 @@ import {
6 tint,
7 } from "@expo/ui/swift-ui/modifiers";
8 import * as Haptics from "expo-haptics";
9 -import { useEffect, useRef } from "react";
9 +import { useRef } from "react";
10 import { View } from "react-native";
11
12 import { AppText } from "./AppText";
@@ -19,11 +19,9 @@ export type { SliderRowProps } from "./SliderRow.types";
19
20 export function SliderRow(props: SliderRowProps) {
21 const { colors } = useControlTheme();
22 - const draft = useRef(props.value);
22 + // The value of the drag in progress; null until the drag moves.
23 + const draft = useRef<number | null>(null);
24 const editing = useRef(false);
24 - useEffect(() => {
25 - if (!editing.current) draft.current = props.value;
26 - }, [props.value]);
25 const commit = (value: number) => {
26 if (props.disabled) return;
27 const next = Math.min(
@@ -60,13 +58,15 @@ export function SliderRow(props: SliderRowProps) {
58 accessibilityValue(props.valueLabel),
59 ]}
60 onValueChange={(value) => {
63 - draft.current = value;
61 // Accessibility adjustments do not begin a touch editing session.
65 - if (!editing.current) commit(value);
62 + if (editing.current) draft.current = value;
63 + else commit(value);
64 }}
65 onEditingChanged={(isEditing) => {
66 editing.current = isEditing;
69 - if (!isEditing) commit(draft.current);
67 + const value = draft.current;
68 + draft.current = null;
69 + if (!isEditing && value !== null) commit(value);
70 }}
71 />
72 </NativeThemeHost>
apps/mobile/src/features/keyboard/CommandPalette.tsx
+16 -7
@@ -504,6 +504,9 @@ export function CommandPalette(props: {
504 results.findIndex((item) => item.key === selection),
505 );
506 const selectedKey = results[selectedIndex]?.key;
507 + // The native list follows the highlighted row. Key presses move it, but so do
508 + // live thread updates and late message matches that reorder or drop the
509 + // selected row under a kept selection, so no single handler owns the scroll.
510 useEffect(() => {
511 if (selectedIndex === 0) {
512 // Centering before the list measures its height scrolls half the first row out of view.
@@ -514,26 +517,30 @@ export function CommandPalette(props: {
517 }, [selectedIndex, selectedKey]);
518
519 const dismissed = useRef(false);
520 + const dismissFallback = useRef<ReturnType<typeof setTimeout> | null>(null);
521 const handleDismissed = useCallback(() => {
522 + if (dismissFallback.current !== null) clearTimeout(dismissFallback.current);
523 + dismissFallback.current = null;
524 if (dismissed.current) return;
525 dismissed.current = true;
526 // Present navigation sheets only after UIKit has dismissed this modal.
527 props.onClose();
528 pendingAction.current?.();
529 }, [props]);
524 -
525 - // iOS may drop onDismiss during presentation or competing sheets; a fallback clears stale palette state.
526 - useEffect(() => {
527 - if (visible) return;
528 - const fallback = setTimeout(handleDismissed, 400);
529 - return () => clearTimeout(fallback);
530 - }, [visible, handleDismissed]);
530 + useEffect(
531 + () => () => {
532 + if (dismissFallback.current !== null) clearTimeout(dismissFallback.current);
533 + },
534 + [],
535 + );
536
537 function close(run?: () => void) {
538 if (closing.current) return;
539 closing.current = true;
540 pendingAction.current = run ?? null;
541 setVisible(false);
542 + // iOS may drop onDismiss during presentation or competing sheets; a fallback clears stale palette state.
543 + dismissFallback.current = setTimeout(handleDismissed, 400);
544 }
545
546 function onCommand(command: HardwareKeyboardCommand) {
@@ -603,6 +610,8 @@ export function CommandPalette(props: {
610 onChangeText={(value) => {
611 setQuery(value);
612 setSelection(null);
613 + // The follow effect stays idle when the top row and its key are unchanged,
614 + // so a touch-scrolled list would otherwise keep its old offset.
615 listRef.current?.scrollToOffset({ offset: 0, animated: false });
616 }}
617 returnKeyType="go"
apps/mobile/src/features/layout/workspace-inspector-pane.tsx
+14 -11
@@ -1,7 +1,9 @@
1 import { useEffect, useRef, useState, type ReactNode } from "react";
2 import Animated, {
3 + cubicBezier,
4 runOnJS,
5 useAnimatedStyle,
6 + useReducedMotion,
7 useSharedValue,
8 withTiming,
9 type SharedValue,
@@ -12,6 +14,9 @@ import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderE
14 import { WORKSPACE_PANE_TIMING } from "./workspace-pane-animation";
15 import { WorkspacePaneDivider } from "./workspace-pane-divider";
16
17 +// CSS form of WORKSPACE_PANE_TIMING's Easing.inOut(Easing.cubic).
18 +const PANE_EASING = cubicBezier(0.65, 0, 0.35, 1);
19 +
20 /** Pass layout props to avoid an import cycle with AdaptiveWorkspaceLayout. */
21 export function WorkspaceInspectorPane(props: {
22 readonly pathname: string;
@@ -32,7 +37,7 @@ export function WorkspaceInspectorPane(props: {
37
38 const inspectorProgress = useSharedValue(inspectorVisible ? 1 : 0);
39 const { renderedInspectorWidth } = props;
35 - const renderedContentWidth = useSharedValue(inspectorWidth ?? 0);
40 + const reduceMotion = useReducedMotion();
41
42 const onClosed = props.onClosed;
43 useEffect(() => {
@@ -56,15 +61,6 @@ export function WorkspaceInspectorPane(props: {
61 resizing,
62 ]);
63
59 - useEffect(() => {
60 - const targetWidth = inspectorWidth ?? 0;
61 - if (!inspectorVisible || resizing) {
62 - renderedContentWidth.set(targetWidth);
63 - return;
64 - }
65 - renderedContentWidth.set(withTiming(targetWidth, WORKSPACE_PANE_TIMING));
66 - }, [inspectorVisible, inspectorWidth, renderedContentWidth, resizing]);
67 -
64 const inspectorStyle = useAnimatedStyle(
65 () => ({
66 opacity: inspectorProgress.value,
@@ -73,7 +69,14 @@ export function WorkspaceInspectorPane(props: {
69 }),
70 [],
71 );
76 - const inspectorContentStyle = useAnimatedStyle(() => ({ width: renderedContentWidth.value }), []);
72 + // A hidden or resizing pane takes its width at once; a visible one eases with the column.
73 + const inspectorContentStyle = {
74 + width: inspectorWidth ?? 0,
75 + transitionProperty: "width",
76 + transitionDuration:
77 + !inspectorVisible || resizing || reduceMotion ? 0 : WORKSPACE_PANE_TIMING.duration,
78 + transitionTimingFunction: PANE_EASING,
79 + } as const;
80 const beginResize = () => {
81 resizeStartWidth.current = inspectorWidth ?? 0;
82 setResizing(true);
apps/mobile/src/native/NativeWorkspaceColumns.ios.tsx
+7 -14
@@ -1,8 +1,10 @@
1 import { requireOptionalNativeModule } from "expo";
2 -import { useEffect, useState } from "react";
2 import { Platform } from "react-native";
3 +import { useDeadlinePassed } from "../lib/clock";
4 import type { NativeLayoutMetrics } from "../lib/reserved-regions";
5 -import { useNativeLayoutMetrics } from "./native-layout-metrics";
5 +import { useNativeLayoutMetrics, useNativeLayoutMetricsDeadline } from "./native-layout-metrics";
6 +
7 +export { NATIVE_METRICS_TIMEOUT_MS } from "./native-layout-metrics";
8
9 const nativeControls = requireOptionalNativeModule<{
10 readonly supportsWorkspaceColumns?: boolean;
@@ -19,24 +21,15 @@ export function nativeWorkspaceColumnsSupportedFor(metrics: NativeLayoutMetrics
21 );
22 }
23
22 -// Binaries without the native no-hinge fallback never report metrics on ordinary
23 -// iPhones running iOS 27.1 or later. Use the compact navigator rather than staying blank.
24 -export const NATIVE_METRICS_TIMEOUT_MS = 1000;
25 -
24 export function useNativeWorkspaceColumnsReady() {
25 const metrics = useNativeLayoutMetrics();
28 - const [timedOut, setTimedOut] = useState(false);
26 + const metricsDeadline = useNativeLayoutMetricsDeadline();
27 const waiting =
28 !(Platform.OS === "ios" && Platform.isPad) &&
29 !!nativeControls?.ViewPrototypes?.T3NativeControls_LayoutMetrics &&
30 metrics === null;
33 -
34 - useEffect(() => {
35 - if (!waiting) return;
36 - const timeout = setTimeout(() => setTimedOut(true), NATIVE_METRICS_TIMEOUT_MS);
37 - return () => clearTimeout(timeout);
38 - }, [waiting]);
39 -
31 + // Without metrics by the deadline, use the compact navigator rather than staying blank.
32 + const timedOut = useDeadlinePassed(waiting ? metricsDeadline : null);
33 return !waiting || timedOut;
34 }
35
apps/mobile/src/native/StackHeader.tsx
+15 -11
@@ -194,22 +194,26 @@ export function NativeStackScreenOptions(props: {
194 const lastAppliedOptionsSignatureRef = useRef<string | undefined>(undefined);
195 const latestOptionFunctionsRef = useRef(new Map<string, (...args: unknown[]) => unknown>());
196 const optionFunctionWrappersRef = useRef(new Map<string, (...args: unknown[]) => unknown>());
197 - const normalizedOptions = useMemo(() => normalizeScreenOptions(props.options), [props.options]);
198 - const stableOptions = normalizedOptions
199 - ? (stabilizeOptionFunctions(
200 - normalizedOptions,
201 - "options",
202 - latestOptionFunctionsRef.current,
203 - optionFunctionWrappersRef.current,
204 - ) as NativeStackNavigationOptions)
205 - : undefined;
197
198 + // Stabilizing records each factory's latest closure, so it runs in the commit
199 + // phase: a render React discards must not leak its closures into the header.
200 + // It runs before the tab check so wrappers already installed in an inactive
201 + // tab's header still call the newest closures.
202 useLayoutEffect(() => {
203 + const normalizedOptions = normalizeScreenOptions(props.options);
204 + const stableOptions = normalizedOptions
205 + ? stabilizeOptionFunctions(
206 + normalizedOptions,
207 + "options",
208 + latestOptionFunctionsRef.current,
209 + optionFunctionWrappersRef.current,
210 + )
211 + : undefined;
212 if (!tabActive) {
213 lastAppliedOptionsSignatureRef.current = undefined;
214 return;
215 }
212 - if (!setOptions || !stableOptions) {
216 + if (!setOptions || !normalizedOptions) {
217 return;
218 }
219 const signature = optionsSignature([stableOptions, props.optionsVersion]);
@@ -229,7 +233,7 @@ export function NativeStackScreenOptions(props: {
233 optionFunctionWrappersRef.current,
234 ) as NativeStackNavigationOptions,
235 );
232 - }, [setOptions, normalizedOptions, props.optionsVersion, stableOptions, tabActive]);
236 + }, [setOptions, props.options, props.optionsVersion, tabActive]);
237
238 useEffect(() => {
239 if (!navigation || !props.listeners) {
apps/mobile/src/native/V5StackHeader.ios.tsx
+2
@@ -268,6 +268,8 @@ export function V5StackHeader(props: {
268 : undefined;
269 const searchOptions = options.headerSearchBarOptions;
270 const autofocusRef = searchOptions?.ref ?? searchRef;
271 + // iOS ignores the native autoFocus prop, and SearchBar's imperative handle changes every
272 + // commit, so a ref callback would refocus on each render; focus once after the header mounts.
273 useEffect(() => {
274 if (!searchOptions?.autoFocus) return;
275 const frame = requestAnimationFrame(() => autofocusRef.current?.focus());
apps/mobile/src/native/native-layout-metrics.tsx
+18 -6
@@ -11,6 +11,10 @@ const NativeLayoutContext = createContext<NativeLayoutMetrics | null>(null);
11 const DeviceTypeContext = createContext<DeviceType>(
12 deriveDeviceType({ isPad: IS_PAD, metrics: null }),
13 );
14 +// Binaries without the native no-hinge fallback never report metrics on ordinary
15 +// iPhones running iOS 27.1 or later; consumers stop waiting at this deadline.
16 +export const NATIVE_METRICS_TIMEOUT_MS = 1000;
17 +const NativeLayoutMetricsDeadlineContext = createContext<number>(0);
18 // Column reservations come from UIKit's layout, outside the resizing navigator.
19 export const NativeColumnLayoutMetricsContext = createContext<NativeLayoutMetrics | null>(null);
20
@@ -38,6 +42,7 @@ export function currentNativeLayoutMetrics() {
42
43 export function NativeLayoutMetricsProvider(props: { readonly children: ReactNode }) {
44 const [metrics, setMetrics] = useState<NativeLayoutMetrics | null>(null);
45 + const [metricsDeadline] = useState(() => Date.now() + NATIVE_METRICS_TIMEOUT_MS);
46 const publish = (next: NativeLayoutMetrics) => {
47 latestMetrics = next;
48 for (const settle of metricsWaiters) settle(next);
@@ -45,12 +50,14 @@ export function NativeLayoutMetricsProvider(props: { readonly children: ReactNod
50 };
51 const deviceType = deriveDeviceType({ isPad: IS_PAD, metrics });
52 return (
48 - <NativeLayoutContext value={metrics}>
49 - <DeviceTypeContext value={deviceType}>
50 - <NativeLayoutObserver onChange={publish} />
51 - {props.children}
52 - </DeviceTypeContext>
53 - </NativeLayoutContext>
53 + <NativeLayoutMetricsDeadlineContext value={metricsDeadline}>
54 + <NativeLayoutContext value={metrics}>
55 + <DeviceTypeContext value={deviceType}>
56 + <NativeLayoutObserver onChange={publish} />
57 + {props.children}
58 + </DeviceTypeContext>
59 + </NativeLayoutContext>
60 + </NativeLayoutMetricsDeadlineContext>
61 );
62 }
63
@@ -58,6 +65,11 @@ export function useNativeLayoutMetrics() {
65 return use(NativeLayoutContext);
66 }
67
68 +/** Epoch ms after which a consumer still waiting for the first metrics gives up. */
69 +export function useNativeLayoutMetricsDeadline() {
70 + return use(NativeLayoutMetricsDeadlineContext);
71 +}
72 +
73 export function useNativeColumnLayoutMetrics() {
74 return use(NativeColumnLayoutMetricsContext);
75 }
apps/mobile/src/reactCompilerCoverage.test.ts
-2
@@ -15,14 +15,12 @@ const metroConfig: Promise<{ transformer: { babelTransformerPath: string } }> =
15 // Remove bailout entries and manual memoization when compilation starts; this check rejects stale entries.
16 const KNOWN_BAILOUTS: Record<string, string> = {
17 "src/components/ComposerAttachmentStrip.tsx": "unsupported syntax",
18 - "src/components/ui/AndroidAnchoredMenu.tsx": "ref read during render",
18 "src/components/ui/Menu.tsx": "ref read during render",
19 "src/features/diffs/nativeReviewDiffSurface.ts": "ref read during render",
20 "src/features/home/thread-swipe-actions.tsx": "ref read during render",
21 "src/features/threads/ThreadArrangementSheet.tsx": "ref read during render",
22 "src/features/voice-input/VoiceInputProvider.tsx": "ref read during render",
23 "src/features/voice-input/useVoiceInputController.ts": "ref read during render",
25 - "src/native/StackHeader.tsx": "ref read during render",
24 "src/native/T3ComposerEditor.ios.tsx": "ref read during render",
25 "src/native/T3ComposerEditor.native.tsx": "ref read during render",
26 };