@devries-cameron20 / t3code-1 / commits / 3caec1a78a
Fork 0

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

refactor(mobile): one inspector column, declared with <Inspector> (#27085)

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

Julius Marminge committed Nov 3, 2026 at 16:53 UTC 3caec1a78a0fc79cc7a117f06ab68f508b0d456b
9 files changed +156 -279
apps/mobile/src/Stack.tsx
-2
@@ -488,7 +488,6 @@ export function workspaceLocationFromState(state: NavigationState) {
488 pathname: path.startsWith("/") ? path : `/${path}`,
489 routeKey: route?.key,
490 routeName: route?.name,
491 - routeKeys: effectiveState.routes.map((stackRoute) => stackRoute.key),
491 };
492 }
493
@@ -536,7 +535,6 @@ function RootStackLayout(props: {
535 pathname={workspaceLocation.pathname}
536 workspaceRouteKey={workspaceLocation.routeKey}
537 workspaceRouteName={workspaceLocation.routeName}
539 - workspaceRouteKeys={workspaceLocation.routeKeys}
538 selectedPullRequestKey={selectedPullRequestKey(props.state)}
539 >
540 {props.children}
apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx
+29 -21
@@ -4,7 +4,7 @@ import { resolveFilesystemReadAccess } from "@t3tools/client-runtime/state/files
4 import { environmentSession } from "../../state/session";
5 import { NativeStackScreenOptions } from "../../native/StackHeader";
6 import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
7 -import { useId, useState } from "react";
7 +import { type ReactNode, useId, useState } from "react";
8 import { Platform, View } from "react-native";
9 import { useSafeAreaInsets } from "react-native-safe-area-context";
10 import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
@@ -37,11 +37,7 @@ import { useEnvironmentQuery } from "../../state/query";
37 import { useEnvironmentPresentation } from "../../state/presentation";
38 import { projectEnvironment } from "../../state/projects";
39 import type { AssetUrlFailureReason } from "../../state/asset-url-state";
40 -import {
41 - useAdaptiveWorkspaceLayout,
42 - useAdaptiveWorkspacePaneRole,
43 - useRegisterWorkspaceInspector,
44 -} from "../layout/AdaptiveWorkspaceLayout";
40 +import { Inspector, useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
41 import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
42 import { ThreadRouteScreen } from "../threads/ThreadRouteScreen";
43 import { FilePreviewLoading, FilePreviewNotice } from "./FilePreviewFeedback";
@@ -432,7 +428,6 @@ function FilesToolbarBottomFade() {
428 }
429
430 export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) {
435 - useAdaptiveWorkspacePaneRole("inspector");
431 const navigation = useNavigation();
432 const { fileInspector, layout } = useAdaptiveWorkspaceLayout();
433 const [searchQuery, setSearchQuery] = useState("");
@@ -589,7 +584,6 @@ export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) {
584 }
585
586 export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
592 - useAdaptiveWorkspacePaneRole("inspector");
587 const navigation = useNavigation();
588 const { fileInspector } = useAdaptiveWorkspaceLayout();
589 const { appearance, setCodeWordBreak } = useAppearancePreferences();
@@ -778,7 +772,15 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
772 renderFiles={() => renderInspector(inspectorHeaderInset)}
773 />
774 );
781 - useRegisterWorkspaceInspector(fileInspector.supported ? renderWorkspaceInspector : undefined);
775 + const inspector = fileInspector.supported ? (
776 + <Inspector>{renderWorkspaceInspector()}</Inspector>
777 + ) : null;
778 + const withInspector = (content: ReactNode) => (
779 + <>
780 + {inspector}
781 + {content}
782 + </>
783 + );
784
785 const fileMenuActions = (() => {
786 if (relativePath === null) return [];
@@ -904,35 +906,41 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
906 };
907
908 if (environmentId === null || (threadId !== null && selectedThread === null)) {
907 - return <LoadingScreen message="Opening file..." messagePlacement="above-spinner" />;
909 + return withInspector(
910 + <LoadingScreen message="Opening file..." messagePlacement="above-spinner" />,
911 + );
912 }
913
914 if (!canReadFiles) {
915 if (fileAccess.isPending) {
912 - return <LoadingScreen message="Checking file access..." messagePlacement="above-spinner" />;
916 + return withInspector(
917 + <LoadingScreen message="Checking file access..." messagePlacement="above-spinner" />,
918 + );
919 }
914 - return (
915 - <FilesUnavailable detail={fileAccess.error ?? "This connection cannot read host files."} />
920 + return withInspector(
921 + <FilesUnavailable detail={fileAccess.error ?? "This connection cannot read host files."} />,
922 );
923 }
924 if (cwd === null) {
919 - return <FilesUnavailable />;
925 + return withInspector(<FilesUnavailable />);
926 }
927
928 if (relativePath === null) {
923 - return (
929 + return withInspector(
930 <View className="flex-1 items-center justify-center bg-sheet px-6">
931 <NativeStackScreenOptions options={{ title: "Files" }} />
932 <EmptyState title="File unavailable" detail="This file path is invalid." />
927 - </View>
933 + </View>,
934 );
935 }
936
937 if (metadataPending) {
932 - return <LoadingScreen message="Opening file..." messagePlacement="above-spinner" />;
938 + return withInspector(
939 + <LoadingScreen message="Opening file..." messagePlacement="above-spinner" />,
940 + );
941 }
942 if (directoryPath !== null) {
935 - return (
943 + return withInspector(
944 <View className={Platform.OS === "android" ? "flex-1 bg-header" : "flex-1 bg-sheet"}>
945 <FilesBrowserHeader
946 projectName={directoryPath}
@@ -965,13 +973,13 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
973 />
974 <FilesToolbarBottomFade />
975 </ScreenContent>
968 - </View>
976 + </View>,
977 );
978 }
979
980 const headerSubtitle = fileHeaderSubtitle(projectName, relativePath);
981
974 - return (
982 + return withInspector(
983 <View className="flex-1 bg-sheet">
984 <FileHeader
985 title={basename(relativePath)}
@@ -1008,6 +1016,6 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
1016 source={fullScreenPreview}
1017 onRequestClose={() => setFullScreenPreview(null)}
1018 />
1011 - </View>
1019 + </View>,
1020 );
1021 }
apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+64 -132
@@ -13,7 +13,6 @@ import type {
13 } from "@t3tools/client-runtime/state/shell";
14 import { EnvironmentId, ThreadId, type SidebarProjectGroupingMode } from "@t3tools/contracts";
15 import { useAtomValue } from "@effect/atom-react";
16 -import { useFocusEffect } from "@react-navigation/native";
16 import { NavigationContext, NavigationRouteContext, useNavigation } from "@react-navigation/native";
17 import {
18 use,
@@ -44,13 +43,11 @@ import {
43 deriveWorkspacePaneLayout,
44 isPrimarySidebarPinned,
45 isWorkspaceListPath,
47 - type WorkspaceAuxiliaryPaneRole,
46 } from "../../lib/layout";
47 import { scopedThreadKey } from "../../lib/scopedEntities";
48 import type { ThreadListFilters } from "../../persistence/mobile-preferences";
49 import { appAtomRegistry } from "../../state/atom-registry";
50 import { useProjects } from "../../state/entities";
53 -import { useThreadCwd } from "../../state/use-selected-thread-worktree";
51 import { environmentThreadShells } from "../../state/threads";
52 import { mobilePreferencesAtom } from "../../state/preferences";
53 import {
@@ -115,38 +112,39 @@ import { SettingsWorkspaceLayout } from "../settings/SettingsWorkspaceLayout";
112
113 export { useAdaptiveWorkspaceLayout };
114
118 -export function useAdaptiveWorkspacePaneRole(role: WorkspaceAuxiliaryPaneRole) {
119 - const { activateAuxiliaryPaneRole } = useAdaptiveWorkspaceLayout();
120 -
121 - useFocusEffect(() => activateAuxiliaryPaneRole(role));
122 -}
123 -
124 -/** Capture inspector navigation contexts. Register on focus events because frozen blurred screens may never clean up. */
125 -export function useRegisterWorkspaceInspector(render: (() => ReactNode) | undefined) {
115 +/**
116 + * Shows its children in the workspace's inspector column while this screen is focused. Register on
117 + * focus events because frozen blurred screens may never clean up.
118 + */
119 +export function Inspector(props: {
120 + readonly children: ReactNode;
121 + /** Opens the column the first time this key registers while its route stays on the stack. */
122 + readonly revealKey?: string;
123 +}) {
124 const { registerWorkspaceInspector } = useAdaptiveWorkspaceLayout();
125 const navigation = use(NavigationContext);
126 const route = use(NavigationRouteContext);
129 -
130 - const wrappedRender = (() => {
131 - if (render === undefined) {
132 - return undefined;
133 - }
134 - return () => (
135 - <NavigationContext.Provider value={navigation}>
136 - <NavigationRouteContext.Provider value={route}>{render()}</NavigationRouteContext.Provider>
137 - </NavigationContext.Provider>
138 - );
139 - })();
127 + const render = () => (
128 + <NavigationContext.Provider value={navigation}>
129 + <NavigationRouteContext.Provider value={route}>
130 + {props.children}
131 + </NavigationRouteContext.Provider>
132 + </NavigationContext.Provider>
133 + );
134 + const reveal =
135 + props.revealKey === undefined || route === undefined
136 + ? undefined
137 + : { routeKey: route.key, key: props.revealKey };
138
139 const focusedRef = useRef(false);
140 const deactivateRef = useRef<(() => void) | null>(null);
141
142 const syncRegistration = useEffectEvent(() => {
145 - if (!focusedRef.current || wrappedRender === undefined) {
143 + if (!focusedRef.current) {
144 deactivateRef.current?.();
145 return;
146 }
149 - deactivateRef.current = registerWorkspaceInspector(wrappedRender);
147 + deactivateRef.current = registerWorkspaceInspector(render, reveal);
148 });
149
150 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Navigation focus events own the inspector registration lifetime.
@@ -173,13 +171,14 @@ export function useRegisterWorkspaceInspector(render: (() => ReactNode) | undefi
171 };
172 }, [navigation]);
173
176 - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Changed pane content replaces the focused inspector registration.
174 + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Changed column content replaces the focused inspector registration.
175 useEffect(() => {
176 if (focusedRef.current) {
177 syncRegistration();
178 }
181 - // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Changed pane content replaces its existing native workspace registration.
182 - }, [wrappedRender]);
179 + // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Changed column content replaces its existing native workspace registration.
180 + }, [props.children, props.revealKey]);
181 + return null;
182 }
183
184 export function AdaptiveWorkspaceLayout(props: {
@@ -187,7 +186,6 @@ export function AdaptiveWorkspaceLayout(props: {
186 readonly pathname: string;
187 readonly workspaceRouteKey: string | undefined;
188 readonly workspaceRouteName: string | undefined;
190 - readonly workspaceRouteKeys: ReadonlyArray<string>;
189 readonly selectedPullRequestKey?: string | null;
190 }) {
191 const preferencesResult = useAtomValue(mobilePreferencesAtom);
@@ -215,7 +213,6 @@ function AdaptiveWorkspaceLayoutContent(
213 readonly pathname: string;
214 readonly workspaceRouteKey: string | undefined;
215 readonly workspaceRouteName: string | undefined;
218 - readonly workspaceRouteKeys: ReadonlyArray<string>;
216 readonly selectedPullRequestKey?: string | null;
217 } & {
218 readonly projectGroupingMode: SidebarProjectGroupingMode;
@@ -237,20 +234,13 @@ function AdaptiveWorkspaceLayoutContent(
234 const workspacePage =
235 Platform.OS === "android" && (androidSettingsOpen || workspace?.state.selectedTab === "usage");
236 const navigation = useNavigation();
240 - const activeRoleOwner = useRef<symbol | null>(null);
237 const [primarySidebarPreferredVisible, setPrimarySidebarPreferredVisible] = useState(true);
242 - const [supplementaryPanePreferredVisible, setSupplementaryPanePreferredVisible] = useState(true);
243 - const [supplementaryPanePreferredWidth, setSupplementaryPanePreferredWidth] = useState<
244 - number | null
245 - >(null);
238 const [fileInspectorPreferredVisible, setFileInspectorPreferredVisible] = useState(true);
239 const [fileInspectorPreferredWidth, setFileInspectorPreferredWidth] = useState<number | null>(
240 null,
241 );
242 const [primarySidebarSearchQuery, setPrimarySidebarSearchQuery] = useState("");
243 const [railOverlay, setRailOverlay] = useState(false);
252 - const [focusedAuxiliaryPaneRole, setFocusedAuxiliaryPaneRole] =
253 - useState<WorkspaceAuxiliaryPaneRole | null>(null);
244 // The compiler can't memoize these derivations: they stay live across later hook calls. Fresh
245 // objects here change the workspace context on every render, so every workspace screen
246 // re-renders on any layout state change, and the inspector registration then loops: each
@@ -356,17 +346,11 @@ function AdaptiveWorkspaceLayoutContent(
346 }),
347 [fileInspectorPreferredWidth, layout, showPrimarySidebar, shouldRenderPrimarySidebar, width],
348 );
359 - const auxiliaryPaneRole: WorkspaceAuxiliaryPaneRole =
360 - focusedAuxiliaryPaneRole ?? (/\/files(?:\/|$)/.test(pathname) ? "inspector" : "supplementary");
361 - const auxiliaryPanePreferredVisible =
362 - !workspacePage &&
363 - (auxiliaryPaneRole === "inspector"
364 - ? fileInspectorPreferredVisible
365 - : supplementaryPanePreferredVisible);
366 - const auxiliaryPanePreferredWidth =
367 - auxiliaryPaneRole === "inspector"
368 - ? fileInspectorPreferredWidth
369 - : supplementaryPanePreferredWidth;
349 + const [workspaceInspector, setWorkspaceInspector] = useState<{
350 + readonly render: () => ReactNode;
351 + readonly active: boolean;
352 + } | null>(null);
353 + const inspectorActive = workspaceInspector?.active ?? false;
354 const panes = useMemo(
355 () =>
356 deriveWorkspacePaneLayout({
@@ -374,18 +358,20 @@ function AdaptiveWorkspaceLayoutContent(
358 viewportWidth: width,
359 nativeWorkspace,
360 primarySidebarPreferredVisible: showPrimarySidebar,
377 - auxiliaryPanePreferredVisible,
378 - auxiliaryPaneRole,
379 - auxiliaryPanePreferredWidth: auxiliaryPanePreferredWidth ?? undefined,
361 + // Only a column a screen fills makes room, so a stale preference can't hide the sidebar.
362 + auxiliaryPanePreferredVisible:
363 + !workspacePage && inspectorActive && fileInspectorPreferredVisible,
364 + auxiliaryPanePreferredWidth: fileInspectorPreferredWidth ?? undefined,
365 }),
366 [
382 - auxiliaryPanePreferredVisible,
383 - auxiliaryPaneRole,
384 - auxiliaryPanePreferredWidth,
367 + fileInspectorPreferredVisible,
368 + fileInspectorPreferredWidth,
369 + inspectorActive,
370 layout,
371 nativeWorkspace,
372 showPrimarySidebar,
373 width,
374 + workspacePage,
375 ],
376 );
377 const activeThread = parseActiveThreadPath(pathname);
@@ -408,44 +394,26 @@ function AdaptiveWorkspaceLayoutContent(
394 selectedThreadRef === null
395 ? null
396 : scopedThreadKey(selectedThreadRef.environmentId, selectedThreadRef.threadId);
411 - const isFilesRoute = props.workspaceRouteName === "ThreadFiles";
412 - // Same resolution the Files screen uses: without a cwd it shows "Files unavailable" and
413 - // registers no inspector, so revealing would only hide the sidebar beside that screen.
414 - const filesCwd = useThreadCwd(isFilesRoute && fileInspector.supported ? selectedThreadRef : null);
415 - // Opening a review or the files route reveals its inspector once per route and thread.
397 // Routes still on the stack remember their reveal, so going back to one keeps the user's choice.
417 - const revealsInspector =
418 - props.workspaceRouteName === "ThreadReview" || (isFilesRoute && filesCwd !== null);
419 - const [revealedInspectors, setRevealedInspectors] = useState<ReadonlyMap<string, string>>(
420 - () => new Map(),
421 - );
422 - if (
423 - revealsInspector &&
424 - props.workspaceRouteKey !== undefined &&
425 - selectedThreadKey !== null &&
426 - revealedInspectors.get(props.workspaceRouteKey) !== selectedThreadKey
427 - ) {
428 - const next = new Map<string, string>();
429 - for (const routeKey of props.workspaceRouteKeys) {
430 - const revealedThreadKey = revealedInspectors.get(routeKey);
431 - if (revealedThreadKey !== undefined) {
432 - next.set(routeKey, revealedThreadKey);
433 - }
434 - }
435 - next.set(props.workspaceRouteKey, selectedThreadKey);
436 - setRevealedInspectors(next);
437 - setFocusedAuxiliaryPaneRole("inspector");
438 - setFileInspectorPreferredVisible(true);
439 - }
440 - const [workspaceInspector, setWorkspaceInspector] = useState<{
441 - readonly render: () => ReactNode;
442 - readonly active: boolean;
443 - } | null>(null);
398 + const revealedInspectors = useRef<ReadonlyMap<string, string>>(new Map());
399 const workspaceInspectorOwner = useRef<symbol | null>(null);
445 - const registerWorkspaceInspector = (render: () => ReactNode) => {
400 + const registerWorkspaceInspector = (
401 + render: () => ReactNode,
402 + reveal?: { readonly routeKey: string; readonly key: string },
403 + ) => {
404 const owner = Symbol("workspace-inspector");
405 workspaceInspectorOwner.current = owner;
406 setWorkspaceInspector({ render, active: true });
407 + if (reveal && revealedInspectors.current.get(reveal.routeKey) !== reveal.key) {
408 + const state = rootStackState(navigation);
409 + const live = new Set(state?.routes.slice(0, state.index + 1).map((route) => route.key));
410 + revealedInspectors.current = new Map(
411 + [...revealedInspectors.current, [reveal.routeKey, reveal.key] as const].filter(
412 + ([routeKey]) => live.has(routeKey) || routeKey === reveal.routeKey,
413 + ),
414 + );
415 + setFileInspectorPreferredVisible(true);
416 + }
417
418 return () => {
419 // Outgoing screens deactivate after incoming registration; only the current owner may deactivate.
@@ -458,19 +426,6 @@ function AdaptiveWorkspaceLayoutContent(
426 const handleWorkspaceInspectorClosed = () => {
427 setWorkspaceInspector((current) => (current !== null && !current.active ? null : current));
428 };
461 - const activateAuxiliaryPaneRole = (role: WorkspaceAuxiliaryPaneRole) => {
462 - const owner = Symbol(role);
463 - activeRoleOwner.current = owner;
464 - setFocusedAuxiliaryPaneRole(role);
465 -
466 - return () => {
467 - if (activeRoleOwner.current !== owner) {
468 - return;
469 - }
470 - activeRoleOwner.current = null;
471 - setFocusedAuxiliaryPaneRole(null);
472 - };
473 - };
429 const setPrimarySidebarVisible = (visible: boolean) => {
430 if (layout.primarySidebarOverlaysContent) {
431 setOverlaySidebar((current) => ({ ...current, visible }));
@@ -508,42 +463,21 @@ function AdaptiveWorkspaceLayoutContent(
463 };
464 const sidebarCommands = primarySidebarPinned ? [] : (["toggleSidebar"] as const);
465 useHardwareKeyboardCommand(sidebarCommands, handleToggleSidebarCommand);
511 - const showAuxiliaryPane = (role: WorkspaceAuxiliaryPaneRole) => {
512 - if (role === "inspector") {
513 - setFocusedAuxiliaryPaneRole("inspector");
514 - setFileInspectorPreferredVisible(true);
515 - return;
516 - }
517 - setFocusedAuxiliaryPaneRole("supplementary");
518 - setSupplementaryPanePreferredVisible(true);
519 - };
466 + const showInspector = () => setFileInspectorPreferredVisible(true);
467 const handleOpenFilesCommand = () => {
468 const activeThread = parseActiveThreadPath(pathname);
469 if (!layout.usesSplitView || !fileInspector.supported || activeThread === null) {
470 return false;
471 }
525 - showAuxiliaryPane("inspector");
526 - if (/\/files(?:\/|$)/.test(pathname)) {
472 + showInspector();
473 + if (props.workspaceRouteName === "ThreadFiles" || props.workspaceRouteName === "ThreadFile") {
474 return true;
475 }
476 navigation.navigate("ThreadFiles", activeThread);
477 return true;
478 };
479 useHardwareKeyboardCommand("files", handleOpenFilesCommand);
533 - const toggleAuxiliaryPane = () => {
534 - if (auxiliaryPaneRole === "inspector") {
535 - setFileInspectorPreferredVisible((current) => !current);
536 - return;
537 - }
538 - setSupplementaryPanePreferredVisible((current) => !current);
539 - };
540 - const setAuxiliaryPaneWidth = (nextWidth: number) => {
541 - if (auxiliaryPaneRole === "inspector") {
542 - setFileInspectorPreferredWidth(nextWidth);
543 - return;
544 - }
545 - setSupplementaryPanePreferredWidth(nextWidth);
546 - };
480 + const toggleAuxiliaryPane = () => setFileInspectorPreferredVisible((current) => !current);
481 /**
482 * The one way to open a workspace tab: replaces the workspace with the tab's list and, when the
483 * window has columns, the page it last showed, keeping any sheet on top. An overlay sidebar
@@ -667,10 +601,9 @@ function AdaptiveWorkspaceLayoutContent(
601 });
602 };
603
670 - const inspectorColumnTargetWidth =
671 - workspaceInspector !== null && workspaceInspector.active && panes.auxiliaryPaneVisible
672 - ? (panes.auxiliaryPaneWidth ?? 0)
673 - : 0;
604 + const inspectorColumnTargetWidth = panes.auxiliaryPaneVisible
605 + ? (panes.auxiliaryPaneWidth ?? 0)
606 + : 0;
607 // Android's split content is a rounded card: keep it off the screen edge like the list card.
608 const contentEndGap = Platform.OS === "android" && layout.usesSplitView ? 4 : 0;
609 const contentTargetWidth = layout.usesSplitView
@@ -874,15 +807,14 @@ function AdaptiveWorkspaceLayoutContent(
807 primarySidebarSearchQuery,
808 startNewTask: handleStartNewTask,
809 selectDetail: handleSelectDetail,
877 - activateAuxiliaryPaneRole,
810 registerWorkspaceInspector,
811 setPrimarySidebarSearchQuery,
880 - showAuxiliaryPane,
812 + showInspector,
813 toggleAuxiliaryPane,
814 togglePrimarySidebar,
815 setPrimarySidebarVisible,
816 openWorkspaceTab,
885 - setAuxiliaryPaneWidth,
817 + setAuxiliaryPaneWidth: setFileInspectorPreferredWidth,
818 composerKeyboardActive,
819 setComposerEditing,
820 sidebarByOrientation,
@@ -1050,7 +982,7 @@ function AdaptiveWorkspaceLayoutContent(
982 active={workspaceInspector?.active ?? false}
983 panes={panes}
984 renderInspector={workspaceInspector?.render}
1053 - setAuxiliaryPaneWidth={setAuxiliaryPaneWidth}
985 + setAuxiliaryPaneWidth={setFileInspectorPreferredWidth}
986 onClosed={handleWorkspaceInspectorClosed}
987 />
988 {shouldRenderNavigationRail && navigationRailWidth > 0 ? (
apps/mobile/src/features/layout/adaptive-workspace-context.ts
+6 -6
@@ -10,7 +10,6 @@ import {
10 deriveWorkspacePaneLayout,
11 type FileInspectorPaneLayout,
12 type Layout,
13 - type WorkspaceAuxiliaryPaneRole,
13 type WorkspacePaneLayout,
14 } from "../../lib/layout";
15
@@ -22,10 +21,12 @@ interface AdaptiveWorkspaceContextValue {
21 readonly startNewTask: () => void;
22 /** Use `useSelectWorkspaceDetail`, which also works outside the layout. */
23 readonly selectDetail?: (detail: WorkspaceDetail, sheet?: WorkspaceDetailSheet) => void;
25 - readonly activateAuxiliaryPaneRole: (role: WorkspaceAuxiliaryPaneRole) => () => void;
26 - readonly registerWorkspaceInspector: (render: () => ReactNode) => () => void;
24 + readonly registerWorkspaceInspector: (
25 + render: () => ReactNode,
26 + reveal?: { readonly routeKey: string; readonly key: string },
27 + ) => () => void;
28 readonly setPrimarySidebarSearchQuery: (query: string) => void;
28 - readonly showAuxiliaryPane: (role: WorkspaceAuxiliaryPaneRole) => void;
29 + readonly showInspector: () => void;
30 readonly toggleAuxiliaryPane: () => void;
31 readonly togglePrimarySidebar: () => void;
32 readonly setPrimarySidebarVisible: (visible: boolean) => void;
@@ -66,10 +67,9 @@ export const AdaptiveWorkspaceContext = createContext<AdaptiveWorkspaceContextVa
67 fileInspector: compactFileInspector,
68 primarySidebarSearchQuery: "",
69 startNewTask: () => undefined,
69 - activateAuxiliaryPaneRole: () => () => undefined,
70 registerWorkspaceInspector: () => () => undefined,
71 setPrimarySidebarSearchQuery: () => undefined,
72 - showAuxiliaryPane: () => undefined,
72 + showInspector: () => undefined,
73 toggleAuxiliaryPane: () => undefined,
74 togglePrimarySidebar: () => undefined,
75 setPrimarySidebarVisible: () => undefined,
apps/mobile/src/features/review/ReviewSheet.tsx
+4 -7
@@ -37,11 +37,7 @@ import { useUniwindTheme } from "../../lib/useUniwindTheme";
37 import { useThreadDraftForThread } from "../../state/use-thread-composer-state";
38 import { EnvironmentConnectionNotice } from "../connection/EnvironmentConnectionNotice";
39 import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
40 -import {
41 - useAdaptiveWorkspaceLayout,
42 - useAdaptiveWorkspacePaneRole,
43 - useRegisterWorkspaceInspector,
44 -} from "../layout/AdaptiveWorkspaceLayout";
40 +import { Inspector, useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
41 import { useSelectedThreadWorktree } from "../../state/use-selected-thread-worktree";
42 import { useReviewCacheForThread } from "./reviewState";
43 import {
@@ -427,7 +423,6 @@ type ReviewSheetProps = StaticScreenProps<{
423 export function ReviewSheet(props: ReviewSheetProps) {
424 const reduceMotion = useReduceMotionEnabled();
425 const { nativeReviewDiffStyle } = useAppearanceCodeSurface();
430 - useAdaptiveWorkspacePaneRole("inspector");
426 const { panes } = useAdaptiveWorkspaceLayout();
427 const navigation = useNavigation();
428 const selectDetail = useSelectWorkspaceDetail();
@@ -634,7 +629,6 @@ export function ReviewSheet(props: ReviewSheetProps) {
629 selectedSection !== null &&
630 parsedDiff.kind === "files" &&
631 NativeReviewDiffView !== null;
637 - useRegisterWorkspaceInspector(showChangedFilesPane ? renderInspector : undefined);
632 const showChangedFilesToggle = panes.supportsAuxiliaryPane && showChangedFilesPane;
633
634 const listHeader = (() => {
@@ -678,6 +672,9 @@ export function ReviewSheet(props: ReviewSheetProps) {
672
673 return (
674 <>
675 + {showChangedFilesPane ? (
676 + <Inspector revealKey={`${environmentId}:${threadId}`}>{renderInspector()}</Inspector>
677 + ) : null}
678 <ReviewHeader
679 environmentId={environmentId}
680 threadId={threadId}
apps/mobile/src/features/threads/ThreadRouteScreen.tsx
+18 -38
@@ -90,11 +90,7 @@ import { EMPTY_ENVIRONMENT_THREAD_STATE } from "@t3tools/client-runtime/state/th
90 import { useProjects } from "../../state/entities";
91 import { projectThreadContentPresentation } from "./threadContentPresentation";
92 import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
93 -import {
94 - useAdaptiveWorkspaceLayout,
95 - useAdaptiveWorkspacePaneRole,
96 - useRegisterWorkspaceInspector,
97 -} from "../layout/AdaptiveWorkspaceLayout";
93 +import { Inspector, useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
94 import { ThreadFileNavigatorPane } from "../files/thread-file-navigator-pane";
95 import {
96 ThreadInspectorContentStack,
@@ -121,11 +117,6 @@ import {
117 import type { ThreadInspectorTarget } from "./thread-inspector-navigation";
118 import { useSelectWorkspaceDetail } from "../workspace/useSelectWorkspaceDetail";
119
124 -function InspectorPaneRoleActivation() {
125 - useAdaptiveWorkspacePaneRole("inspector");
126 - return null;
127 -}
128 -
120 function firstRouteParam(value: string | string[] | undefined): string | null {
121 const first = Array.isArray(value) ? value[0] : value;
122 return first === undefined || first.trim().length === 0 ? null : first;
@@ -353,7 +344,7 @@ function ThreadRouteContent(
344 ) {
345 const { themeVariables } = useAppearancePreferences();
346 const headerColor = themeVariables["--color-header"];
356 - const { fileInspector, layout, panes, showAuxiliaryPane, toggleAuxiliaryPane } =
347 + const { fileInspector, layout, panes, showInspector, toggleAuxiliaryPane } =
348 useAdaptiveWorkspaceLayout();
349 const { connectionState } = useRemoteConnectionStatus();
350 const { onReconnectEnvironment } = useRemoteConnections();
@@ -487,27 +478,7 @@ function ThreadRouteContent(
478 : chosenInspectorMode;
479 return mode === "files" && selectedThreadCwd === null ? null : mode;
480 })();
490 - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- closes the workspace navigator's auxiliary pane when the thread has no cwd for the file inspector
491 - useEffect(() => {
492 - if (
493 - props.inspectorPresentation === undefined &&
494 - fileInspector.supported &&
495 - selectedThreadCwd === null &&
496 - inspectorMode === null &&
497 - panes.auxiliaryPaneVisible
498 - ) {
499 - toggleAuxiliaryPane();
500 - }
501 - }, [
502 - fileInspector.supported,
503 - inspectorMode,
504 - panes.auxiliaryPaneVisible,
505 - props.inspectorPresentation,
506 - selectedThreadCwd,
507 - toggleAuxiliaryPane,
508 - ]);
509 -
510 - const revealPreview = useEffectEvent(() => showAuxiliaryPane("inspector"));
481 + const revealPreview = useEffectEvent(() => showInspector());
482 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- opens the workspace navigator's inspector pane when route params bring a preview target
483 useEffect(() => {
484 if (previewTarget) revealPreview();
@@ -588,7 +559,7 @@ function ThreadRouteContent(
559 }
560 navigation.setParams({ inspector: undefined });
561 setChosenInspectorMode("git");
591 - showAuxiliaryPane("inspector");
562 + showInspector();
563 };
564 const handleOpenFilesInspector = () => {
565 if (selectedThread === null || selectedThreadCwd === null) {
@@ -603,7 +574,7 @@ function ThreadRouteContent(
574 }
575 navigation.setParams({ inspector: undefined });
576 setChosenInspectorMode(props.renderInspector === undefined ? "files" : "route");
606 - showAuxiliaryPane("inspector");
577 + showInspector();
578 };
579 const handleToggleInspector = () => {
580 if (inspectorMode === null) {
@@ -678,9 +649,7 @@ function ThreadRouteContent(
649 renderRoute={props.renderInspector ? renderRouteInspector : undefined}
650 />
651 );
681 - const activeInspectorRenderer =
682 - props.inspectorPresentation || inspectorMode === null ? undefined : renderInspectorStack;
683 - useRegisterWorkspaceInspector(activeInspectorRenderer);
652 + const showsInspector = !props.inspectorPresentation && inspectorMode !== null;
653
654 const handleOpenConnectionEditor = () => {
655 void navigation.navigate("Connections");
@@ -1128,7 +1097,18 @@ function ThreadRouteContent(
1097
1098 return (
1099 <>
1131 - {activeInspectorRenderer ? <InspectorPaneRoleActivation /> : null}
1100 + {showsInspector ? (
1101 + <Inspector
1102 + // A route's own inspector (files) opens once per thread; going back keeps the user's choice.
1103 + revealKey={
1104 + props.renderInspector !== undefined && selectedThreadCwd !== null
1105 + ? (routeThreadIdentity ?? undefined)
1106 + : undefined
1107 + }
1108 + >
1109 + {renderInspectorStack()}
1110 + </Inspector>
1111 + ) : null}
1112
1113 {renderThreadRouteBody()}
1114 </>
apps/mobile/src/features/threads/thread-inspector-navigation.test.tsx
+8 -11
@@ -221,7 +221,7 @@ it("keeps a focused inspector registered across renders and updates its content"
221 },
222 );
223 const exports: {
224 - useRegisterWorkspaceInspector?: (render: (() => React.ReactNode) | undefined) => void;
224 + Inspector?: (props: { readonly children: React.ReactNode }) => null;
225 } = {};
226 const load = (name: string) => {
227 if (name === "react" || name.startsWith("react/")) return requireMobile(name);
@@ -233,22 +233,19 @@ it("keeps a focused inspector registered across renders and updates its content"
233 return {
234 NavigationContext: navigationContext,
235 NavigationRouteContext: routeContext,
236 - useFocusEffect: (callback: () => (() => void) | undefined) =>
237 - React.useEffect(callback, [callback]),
236 };
237 return {};
238 };
239 new Function("require", "exports", compiled.code)(load, exports);
242 - const useRegisterWorkspaceInspector = exports.useRegisterWorkspaceInspector!;
243 - function Screen({ render }: { render: (() => React.ReactNode) | undefined }) {
244 - useRegisterWorkspaceInspector(render);
245 - return null;
240 + const Inspector = exports.Inspector!;
241 + function Screen({ content }: { content: string | undefined }) {
242 + return content === undefined ? null : <Inspector>{content}</Inspector>;
243 }
244 const root = createRoot(document.createElement("div"));
245 using _root = { [Symbol.dispose]: () => act(() => root.unmount()) };
249 - const render = (content: (() => React.ReactNode) | undefined) =>
250 - act(() => root.render(<Screen render={content} />));
251 - const first = () => "first";
246 + const render = (content: string | undefined) =>
247 + act(() => root.render(<Screen content={content} />));
248 + const first = "first";
249 render(first);
250 registerWorkspaceInspector.mockClear();
251 deactivate.mockClear();
@@ -256,7 +253,7 @@ it("keeps a focused inspector registered across renders and updates its content"
253 render(first);
254 expect(registerWorkspaceInspector).not.toHaveBeenCalled();
255 expect(deactivate).not.toHaveBeenCalled();
259 - const second = () => "second";
256 + const second = "second";
257 render(second);
258 expect(registerWorkspaceInspector).toHaveBeenCalledTimes(1);
259 const paneContainer = document.createElement("div");
apps/mobile/src/lib/layout.test.ts
-2
@@ -151,7 +151,6 @@ describe("deriveWorkspacePaneLayout", () => {
151 nativeWorkspace: true,
152 primarySidebarPreferredVisible,
153 auxiliaryPanePreferredVisible: true,
154 - auxiliaryPaneRole: "inspector",
154 }),
155 ).toMatchObject({
156 primarySidebarVisible: primarySidebarPreferredVisible,
@@ -170,7 +169,6 @@ describe("deriveWorkspacePaneLayout", () => {
169 viewportWidth: 1_024,
170 primarySidebarPreferredVisible: false,
171 auxiliaryPanePreferredVisible: true,
173 - auxiliaryPaneRole: "inspector",
172 }),
173 ).toMatchObject({
174 primarySidebarVisible: false,
apps/mobile/src/lib/layout.ts
+27 -60
@@ -12,7 +12,6 @@ const SPLIT_LAYOUT_MIN_HEIGHT = 600;
12 const SPLIT_SIDEBAR_MIN_WIDTH = 280;
13 const SPLIT_SIDEBAR_DEFAULT_MAX_WIDTH = 380;
14
15 -const AUXILIARY_PANE_MIN_CONTENT_WIDTH = 960;
15 export const CHAT_CONTENT_MAX_WIDTH = 960;
16 // Limit Android reading width for wide foldables and keyboard-open split views.
17 export const ANDROID_READING_MAX_WIDTH = 640;
@@ -98,8 +97,6 @@ export function deriveThreadFeedInitialContentInset(input: {
97 return { bottom: Math.max(0, input.bottomContentInset) };
98 }
99
101 -export type WorkspaceAuxiliaryPaneRole = "supplementary" | "inspector";
102 -
100 export function deriveLayout(input: {
101 readonly width: number;
102 readonly height: number;
@@ -207,76 +204,46 @@ export function deriveWorkspacePaneLayout(input: {
204 readonly nativeWorkspace?: boolean;
205 readonly primarySidebarPreferredVisible: boolean;
206 readonly auxiliaryPanePreferredVisible: boolean;
210 - readonly auxiliaryPaneRole?: WorkspaceAuxiliaryPaneRole;
207 readonly auxiliaryPanePreferredWidth?: number;
208 }): WorkspacePaneLayout {
209 const viewportWidth = Math.max(0, input.viewportWidth);
214 - const auxiliaryPaneRole = input.auxiliaryPaneRole ?? "supplementary";
210 const preferredPrimarySidebarVisible =
211 input.layout.usesSplitView && input.primarySidebarPreferredVisible;
212 const preferredPrimarySidebarWidth =
213 preferredPrimarySidebarVisible && !input.layout.primarySidebarOverlaysContent
214 ? (input.layout.listPaneWidth ?? 0) + (input.layout.listPaneGap ?? 0)
215 : 0;
221 -
222 - if (auxiliaryPaneRole === "inspector") {
223 - const fileInspector = deriveFileInspectorPaneLayout({
224 - layout: input.layout,
225 - viewportWidth,
226 - preferredWidth: input.auxiliaryPanePreferredWidth,
227 - reservedLeadingWidth: preferredPrimarySidebarWidth,
228 - });
229 - const auxiliaryPaneVisible = fileInspector.supported && input.auxiliaryPanePreferredVisible;
230 - const primarySidebarSuppressedByAuxiliary =
231 - !input.nativeWorkspace &&
232 - preferredPrimarySidebarVisible &&
233 - !input.layout.primarySidebarOverlaysContent &&
234 - auxiliaryPaneVisible &&
235 - fileInspector.width !== null &&
236 - input.layout.listPaneWidth !== null &&
237 - viewportWidth -
238 - input.layout.listPaneWidth -
239 - (input.layout.listPaneGap ?? 0) -
240 - fileInspector.width <
241 - FILE_INSPECTOR_MIN_MAIN_WIDTH;
242 - const primarySidebarVisible =
243 - preferredPrimarySidebarVisible && !primarySidebarSuppressedByAuxiliary;
244 - const primarySidebarWidth = primarySidebarVisible ? preferredPrimarySidebarWidth : 0;
245 -
246 - return {
247 - primarySidebarVisible,
248 - primarySidebarWhenExpanded: input.primarySidebarPreferredVisible,
249 - primarySidebarSuppressedByAuxiliary,
250 - contentPaneWidth: Math.max(0, viewportWidth - primarySidebarWidth),
251 - supportsAuxiliaryPane: fileInspector.supported,
252 - auxiliaryPaneVisible,
253 - auxiliaryPaneWidth: fileInspector.width,
254 - };
255 - }
256 -
257 - const contentPaneWidth = Math.max(0, viewportWidth - preferredPrimarySidebarWidth);
258 - const supportsAuxiliaryPane =
259 - input.layout.usesSplitView && contentPaneWidth >= AUXILIARY_PANE_MIN_CONTENT_WIDTH;
260 - const auxiliaryPaneVisible = supportsAuxiliaryPane && input.auxiliaryPanePreferredVisible;
261 - const defaultAuxiliaryPaneWidth = clamp(
262 - Math.round(contentPaneWidth * 0.28),
263 - AUXILIARY_PANE_MIN_WIDTH,
264 - AUXILIARY_PANE_DEFAULT_MAX_WIDTH,
265 - );
216 + const fileInspector = deriveFileInspectorPaneLayout({
217 + layout: input.layout,
218 + viewportWidth,
219 + preferredWidth: input.auxiliaryPanePreferredWidth,
220 + reservedLeadingWidth: preferredPrimarySidebarWidth,
221 + });
222 + const auxiliaryPaneVisible = fileInspector.supported && input.auxiliaryPanePreferredVisible;
223 + const primarySidebarSuppressedByAuxiliary =
224 + !input.nativeWorkspace &&
225 + preferredPrimarySidebarVisible &&
226 + !input.layout.primarySidebarOverlaysContent &&
227 + auxiliaryPaneVisible &&
228 + fileInspector.width !== null &&
229 + input.layout.listPaneWidth !== null &&
230 + viewportWidth -
231 + input.layout.listPaneWidth -
232 + (input.layout.listPaneGap ?? 0) -
233 + fileInspector.width <
234 + FILE_INSPECTOR_MIN_MAIN_WIDTH;
235 + const primarySidebarVisible =
236 + preferredPrimarySidebarVisible && !primarySidebarSuppressedByAuxiliary;
237 + const primarySidebarWidth = primarySidebarVisible ? preferredPrimarySidebarWidth : 0;
238
239 return {
268 - primarySidebarVisible: preferredPrimarySidebarVisible,
240 + primarySidebarVisible,
241 primarySidebarWhenExpanded: input.primarySidebarPreferredVisible,
270 - primarySidebarSuppressedByAuxiliary: false,
271 - contentPaneWidth,
272 - supportsAuxiliaryPane,
242 + primarySidebarSuppressedByAuxiliary,
243 + contentPaneWidth: Math.max(0, viewportWidth - primarySidebarWidth),
244 + supportsAuxiliaryPane: fileInspector.supported,
245 auxiliaryPaneVisible,
274 - auxiliaryPaneWidth: supportsAuxiliaryPane
275 - ? constrainAuxiliaryPaneWidth({
276 - preferredWidth: input.auxiliaryPanePreferredWidth ?? defaultAuxiliaryPaneWidth,
277 - availableWidth: contentPaneWidth,
278 - })
279 - : null,
246 + auxiliaryPaneWidth: fileInspector.width,
247 };
248 }
249