Skip to content

Commit 8c0670b

Browse files
fix(mobile): one way to select a page, so split view stops pushing (#24742)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent e9d6125 commit 8c0670b

38 files changed

Lines changed: 654 additions & 877 deletions

‎apps/mobile/src/App.tsx‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import { StatusBar } from "react-native";
66
import { GestureHandlerRootView } from "react-native-gesture-handler";
77
import { KeyboardProvider } from "react-native-keyboard-controller";
88
import { SafeAreaProvider } from "react-native-safe-area-context";
9-
import { createStaticNavigation, getStateFromPath } from "@react-navigation/native";
9+
import {
10+
createNavigationContainerRef,
11+
createStaticNavigation,
12+
getActionFromState,
13+
getStateFromPath,
14+
} from "@react-navigation/native";
1015

1116
import { RegistryContext } from "@effect/atom-react";
1217
import { ProjectChipIconRasterizer } from "./native/ProjectChipIconImages";
@@ -38,6 +43,7 @@ import {
3843
recordWorkspaceSelections,
3944
settingsLinkPage,
4045
} from "./features/workspace/workspace-selection-store";
46+
import { workspaceDetailLinkAction } from "./features/workspace/workspace-detail-selection";
4147
import { NativeLayoutMetricsProvider } from "./native/native-layout-metrics";
4248

4349
import "../global.css";
@@ -54,6 +60,13 @@ const appLinking = {
5460
config: { initialRouteName: "Home" },
5561
filter: shouldHandleAppLink,
5662
getInitialURL: async () => (await Linking.getInitialURL()) ?? (await launchWorkspaceURL()),
63+
getActionFromState: (
64+
state: Parameters<typeof getActionFromState>[0],
65+
options: Parameters<typeof getActionFromState>[1],
66+
): ReturnType<typeof getActionFromState> =>
67+
// Our router handles the selection; React Navigation's type only lists its own actions.
68+
(workspaceDetailLinkAction(state) as ReturnType<typeof getActionFromState>) ??
69+
getActionFromState(state, options),
5770
getStateFromPath: (path: string, options: Parameters<typeof getStateFromPath>[1]) =>
5871
restoreSettingsLinkState(
5972
restoreDraftLinkState(getStateFromPath(path, options), path),
@@ -62,6 +75,7 @@ const appLinking = {
6275
};
6376

6477
const Navigation = createStaticNavigation(RootStack);
78+
const navigationRef = createNavigationContainerRef();
6579

6680
function SplashScreenCoordinator() {
6781
const { isReady } = useAppearancePreferences();
@@ -116,7 +130,9 @@ function AppContent() {
116130
<NativeLayoutMetricsProvider>
117131
<IncomingShareProvider>
118132
<Navigation
133+
ref={navigationRef}
119134
linking={appLinking}
135+
onReady={() => recordWorkspaceSelections(navigationRef.getRootState())}
120136
theme={navigationTheme}
121137
onStateChange={recordWorkspaceSelections}
122138
/>

‎apps/mobile/src/Stack.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ import { nativeHeaderScrollEdgeEffects } from "./native/StackHeader";
149149
import { HORIZONTAL_FORM_SHEET_OPTIONS, formSheetDetents } from "./native/sheet-surface";
150150
import { useThreadOutboxDrain } from "./state/use-thread-outbox-drain";
151151
import { useComposerAttachmentUploadWorker } from "./state/composer-attachment-uploads";
152+
import {
153+
selectWorkspaceDetail,
154+
workspaceDetailRouter,
155+
} from "./features/workspace/workspace-detail-selection";
152156

153157
const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
154158

@@ -525,7 +529,12 @@ function RootStackLayout(props: {
525529
if (!transition.shareIdToPresent) {
526530
return;
527531
}
528-
navigation.navigate("Thread", { draft: { incomingShareId: transition.shareIdToPresent } });
532+
navigation.dispatch(
533+
selectWorkspaceDetail({
534+
name: "Thread",
535+
params: { draft: { incomingShareId: transition.shareIdToPresent } },
536+
}),
537+
);
529538
}, [navigation, pendingShare, props.state]);
530539

531540
return (
@@ -599,6 +608,7 @@ function NotFoundScreen() {
599608

600609
const RootStackConfig = createWorkspaceStackNavigator({
601610
initialRouteName: "Home",
611+
UNSTABLE_router: workspaceDetailRouter,
602612
// React Navigation calls layouts inline; compiled components would share the navigator's memo cache.
603613
layout: (props) => <RootStackLayout {...props} />,
604614
screenOptions: {

‎apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { AudioFilePreview } from "./AudioFilePreview";
2222
import { EmptyState } from "../../components/ui/EmptyState";
2323
import { FilePreviewModal, type FilePreviewSource } from "../../components/FilePreviewModal";
2424
import { LoadingScreen } from "../../components/LoadingScreen";
25-
import { resolveFileSelectionNavigationAction } from "../../lib/adaptive-navigation";
2625
import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
2726
import { isPdfFile } from "../../lib/filePreview";
2827
import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
@@ -478,10 +477,7 @@ export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) {
478477
navigation.navigate("NewTaskFile", params);
479478
return;
480479
}
481-
const navigationAction = resolveFileSelectionNavigationAction({
482-
hasPersistentFileInspector: hasFileInspector,
483-
});
484-
if (navigationAction === "replace") {
480+
if (hasFileInspector) {
485481
navigation.dispatch(StackActions.replace("ThreadFile", params));
486482
return;
487483
}

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ import { HomeScreen } from "./HomeScreen";
2828
import { HomeHeader } from "./HomeHeader";
2929
import { useHomeListOptions } from "./home-list-options";
3030
import { useAtomValueWhileVisible, useHomeRouteVisible } from "./home-route-visibility";
31-
import { useHomeThreadRouteSelection, useHomeThreadSelection } from "./home-thread-navigation";
3231
import { buildHomeProjectScopes } from "./homeThreadList";
3332
import { usePendingTaskListActions } from "./usePendingTaskListActions";
3433
import { useThreadListActions } from "./useThreadListActions";
3534
import { getConnectionAwareBrandHeaderOptions } from "./WorkspaceConnectionTitle";
3635
import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
3736
import { openSettings } from "../settings/settings-navigation";
3837
import { useSelectWorkspaceTab } from "../workspace/useSelectWorkspaceTab";
38+
import { useSelectWorkspaceDetail } from "../workspace/useSelectWorkspaceDetail";
3939

4040
export function HomeRouteScreen() {
4141
const { width: windowWidth } = useWindowDimensions();
@@ -45,6 +45,7 @@ export function HomeRouteScreen() {
4545
const headerWidth = nativePrimaryColumn ? (columnMetrics?.width ?? windowWidth) : windowWidth;
4646
const { layout, panes, primarySidebarSearchQuery, setPrimarySidebarSearchQuery, startNewTask } =
4747
useAdaptiveWorkspaceLayout();
48+
const selectDetail = useSelectWorkspaceDetail();
4849
const projects = useProjects();
4950
// Stop rebuilding the streaming thread list while Thread covers Home.
5051
const visible = useHomeRouteVisible();
@@ -67,8 +68,18 @@ export function HomeRouteScreen() {
6768
else if (workspace) workspace.dispatch({ type: "query", query, tab: "threads" });
6869
else setLocalSearchQuery(query);
6970
};
70-
const handleSelectThread = useHomeThreadSelection();
71-
const selectThreadRoute = useHomeThreadRouteSelection();
71+
const handleSelectThread = useCallback(
72+
(thread: EnvironmentThreadShell) =>
73+
selectDetail({
74+
name: "Thread",
75+
params: { environmentId: String(thread.environmentId), threadId: String(thread.id) },
76+
}),
77+
[selectDetail],
78+
);
79+
const selectThreadRoute = useCallback(
80+
(params: ReactNavigation.RootParamList["Thread"]) => selectDetail({ name: "Thread", params }),
81+
[selectDetail],
82+
);
7283
const handleNewThreadOnBranch = useCallback(
7384
(thread: EnvironmentThreadShell) => {
7485
selectThreadRoute({
@@ -104,7 +115,8 @@ export function HomeRouteScreen() {
104115
unsettleThread,
105116
} = useThreadListActions();
106117
const pendingTasks = usePendingNewTasks();
107-
const { openPendingTask, confirmDeletePendingTask } = usePendingTaskListActions();
118+
const { openPendingTask, confirmDeletePendingTask } =
119+
usePendingTaskListActions(selectThreadRoute);
108120
const environments = useMemo(() => {
109121
const connectionStateByEnvironmentId = new Map(
110122
workspaceEnvironments.map(

0 commit comments

Comments
 (0)