Skip to content

Commit b76763a

Browse files
feat(mobile): without an inspector column, the inspector is a sheet
The thread screen chose by window width where its files and git inspectors went: the column, or the ThreadFiles and GitOverview routes. The screen now always asks the shell to show its inspector. Where the window has a column, the column opens. Otherwise the shell presents the same content in a sheet, which opens only on request, stays with the route that opened it, and closes on dismiss or when another page is selected. The inspector's top inset now comes from where it renders, so it sits flush in a sheet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 62fffd1 commit b76763a

5 files changed

Lines changed: 219 additions & 74 deletions

File tree

‎apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx‎

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderE
8181
import { PaneContext } from "../../components/ui/Pane";
8282
import { WORKSPACE_PANE_TIMING } from "./workspace-pane-animation";
8383
import { WorkspaceInspectorPane } from "./workspace-inspector-pane";
84+
import { WorkspaceInspectorSheet } from "./workspace-inspector-sheet";
8485
import {
8586
WorkspaceContentWidthContext,
8687
WorkspaceSettledContentWidthContext,
@@ -129,11 +130,6 @@ export function Inspector(props: {
129130
</NavigationRouteContext.Provider>
130131
</NavigationContext.Provider>
131132
);
132-
const reveal =
133-
props.revealKey === undefined || route === undefined
134-
? undefined
135-
: { routeKey: route.key, key: props.revealKey };
136-
137133
const focusedRef = useRef(false);
138134
const deactivateRef = useRef<(() => void) | null>(null);
139135

@@ -142,7 +138,7 @@ export function Inspector(props: {
142138
deactivateRef.current?.();
143139
return;
144140
}
145-
deactivateRef.current = registerWorkspaceInspector(render, reveal);
141+
deactivateRef.current = registerWorkspaceInspector(render, route?.key, props.revealKey);
146142
});
147143

148144
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Navigation focus events own the inspector registration lifetime.
@@ -356,7 +352,17 @@ function AdaptiveWorkspaceLayoutContent(
356352
const [workspaceInspector, setWorkspaceInspector] = useState<{
357353
readonly render: () => ReactNode;
358354
readonly active: boolean;
355+
readonly routeKey: string | undefined;
359356
} | null>(null);
357+
// Without a column the inspector is a sheet, opened only on request for the route on top, and
358+
// shown again when that route returns to the top.
359+
const [inspectorSheetRoute, setInspectorSheetRoute] = useState<string | null>(null);
360+
const inspectorSheetOpen =
361+
!fileInspector.supported &&
362+
!workspacePage &&
363+
inspectorSheetRoute !== null &&
364+
workspaceInspector?.active === true &&
365+
workspaceInspector.routeKey === inspectorSheetRoute;
360366
const inspectorActive = workspaceInspector?.active ?? false;
361367
const panes = useMemo(
362368
() =>
@@ -388,17 +394,22 @@ function AdaptiveWorkspaceLayoutContent(
388394
const workspaceInspectorOwner = useRef<symbol | null>(null);
389395
const registerWorkspaceInspector = (
390396
render: () => ReactNode,
391-
reveal?: { readonly routeKey: string; readonly key: string },
397+
routeKey: string | undefined,
398+
revealKey?: string,
392399
) => {
393400
const owner = Symbol("workspace-inspector");
394401
workspaceInspectorOwner.current = owner;
395-
setWorkspaceInspector({ render, active: true });
396-
if (reveal && revealedInspectors.current.get(reveal.routeKey) !== reveal.key) {
402+
setWorkspaceInspector({ render, active: true, routeKey });
403+
if (
404+
routeKey !== undefined &&
405+
revealKey !== undefined &&
406+
revealedInspectors.current.get(routeKey) !== revealKey
407+
) {
397408
const state = rootStackState(navigation);
398409
const live = new Set(state?.routes.slice(0, state.index + 1).map((route) => route.key));
399410
revealedInspectors.current = new Map(
400-
[...revealedInspectors.current, [reveal.routeKey, reveal.key] as const].filter(
401-
([routeKey]) => live.has(routeKey) || routeKey === reveal.routeKey,
411+
[...revealedInspectors.current, [routeKey, revealKey] as const].filter(
412+
([key]) => live.has(key) || key === routeKey,
402413
),
403414
);
404415
setFileInspectorPreferredVisible(true);
@@ -452,7 +463,16 @@ function AdaptiveWorkspaceLayoutContent(
452463
};
453464
const sidebarCommands = primarySidebarPinned ? [] : (["toggleSidebar"] as const);
454465
useHardwareKeyboardCommand(sidebarCommands, handleToggleSidebarCommand);
455-
const showInspector = () => setFileInspectorPreferredVisible(true);
466+
const showInspector = () => {
467+
if (fileInspector.supported) {
468+
setFileInspectorPreferredVisible(true);
469+
setInspectorSheetRoute(null);
470+
return;
471+
}
472+
const state = rootStackState(navigation);
473+
const top = workspaceRoutesOf(state?.routes.slice(0, state.index + 1) ?? []).workspace.at(-1);
474+
setInspectorSheetRoute(top?.key ?? null);
475+
};
456476
const handleOpenFilesCommand = () => {
457477
const activeThread = parseActiveThreadPath(pathname);
458478
if (!layout.usesSplitView || !fileInspector.supported || activeThread === null) {
@@ -466,7 +486,13 @@ function AdaptiveWorkspaceLayoutContent(
466486
return true;
467487
};
468488
useHardwareKeyboardCommand("files", handleOpenFilesCommand);
469-
const toggleAuxiliaryPane = () => setFileInspectorPreferredVisible((current) => !current);
489+
const toggleAuxiliaryPane = () => {
490+
if (fileInspector.supported) {
491+
setFileInspectorPreferredVisible((current) => !current);
492+
setInspectorSheetRoute(null);
493+
} else if (inspectorSheetOpen) setInspectorSheetRoute(null);
494+
else showInspector();
495+
};
470496
/**
471497
* The one way to open a workspace tab: replaces the workspace with the tab's list and, when the
472498
* window has columns, the page it last showed, keeping any sheet on top. An overlay sidebar
@@ -502,6 +528,7 @@ function AdaptiveWorkspaceLayoutContent(
502528
threadSelectionDeferral.run(() => {
503529
if (Platform.OS === "android") Keyboard.dismiss();
504530
setFileInspectorPreferredVisible(false);
531+
setInspectorSheetRoute(null);
505532
if (layout.variant === "medium") setPrimarySidebarVisible(false);
506533
workspace?.dispatch({
507534
type: "select",
@@ -783,6 +810,11 @@ function AdaptiveWorkspaceLayoutContent(
783810
sidebarByOrientation,
784811
};
785812

813+
const inspectorSheet = (
814+
<WorkspaceInspectorSheet open={inspectorSheetOpen} onClose={() => setInspectorSheetRoute(null)}>
815+
{workspaceInspector?.render()}
816+
</WorkspaceInspectorSheet>
817+
);
786818
if (nativeWorkspace) {
787819
return (
788820
<HomeListOptionsProvider
@@ -791,9 +823,14 @@ function AdaptiveWorkspaceLayoutContent(
791823
>
792824
<AdaptiveWorkspaceContext value={contextValue}>
793825
<NativeWorkspaceInspectorContext
794-
value={{ render: workspaceInspector?.render, visible: inspectorColumnTargetWidth > 0 }}
826+
value={{
827+
// Without a column the sheet shows it; the hidden native column must not mount it too.
828+
render: fileInspector.supported ? workspaceInspector?.render : undefined,
829+
visible: inspectorColumnTargetWidth > 0,
830+
}}
795831
>
796832
{props.children}
833+
{inspectorSheet}
797834
</NativeWorkspaceInspectorContext>
798835
</AdaptiveWorkspaceContext>
799836
</HomeListOptionsProvider>
@@ -952,6 +989,7 @@ function AdaptiveWorkspaceLayoutContent(
952989
onClosed={handleWorkspaceInspectorClosed}
953990
/>
954991
</PaneContext>
992+
{inspectorSheet}
955993
{shouldRenderNavigationRail && navigationRailWidth > 0 ? (
956994
// The rail reserves its slot above and draws over the panes, so it can widen over
957995
// the list in place. It takes the whole workspace only while it is open.

‎apps/mobile/src/features/layout/adaptive-workspace-context.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ interface AdaptiveWorkspaceContextValue {
2323
readonly selectDetail?: (detail: WorkspaceDetail, sheet?: WorkspaceDetailSheet) => void;
2424
readonly registerWorkspaceInspector: (
2525
render: () => ReactNode,
26-
reveal?: { readonly routeKey: string; readonly key: string },
26+
routeKey: string | undefined,
27+
revealKey?: string,
2728
) => () => void;
2829
readonly setPrimarySidebarSearchQuery: (query: string) => void;
30+
/** Opens the inspector: its column where the window has one, otherwise a sheet. */
2931
readonly showInspector: () => void;
3032
readonly toggleAuxiliaryPane: () => void;
3133
/**
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { createContext, useRef, useState, type ReactNode } from "react";
2+
import { Platform, View } from "react-native";
3+
import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context";
4+
import { FormSheet } from "react-native-screens";
5+
import { useResolveClassNames } from "uniwind";
6+
7+
import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderErrorBoundary";
8+
import { PaneContext } from "../../components/ui/Pane";
9+
import { RoutedFormSheetContext } from "../../components/ui/RoutedFormSheetContext";
10+
import { formSheetDetents } from "../../native/sheet-surface";
11+
12+
/**
13+
* Closes the inspector sheet around the inspector, then runs `then` once it is gone: a route
14+
* presented over a sheet that isn't one of the stack's own would race its dismissal.
15+
*/
16+
export const InspectorSheetContext = createContext<((then?: () => void) => void) | null>(null);
17+
18+
/** The inspector where the window has no column for it. Its content draws its own bar. */
19+
export function WorkspaceInspectorSheet(props: {
20+
readonly open: boolean;
21+
readonly onClose: () => void;
22+
readonly children: ReactNode;
23+
}) {
24+
const containerStyle = useResolveClassNames(Platform.OS === "android" ? "bg-header" : "bg-sheet");
25+
const insets = useSafeAreaInsets();
26+
// Stays mounted until the sheet has finished closing, so it doesn't empty as it slides away.
27+
// Each opening gets a fresh native sheet, even one that starts while the last is closing.
28+
const [presented, setPresented] = useState({
29+
open: props.open,
30+
mounted: props.open,
31+
session: 0,
32+
});
33+
if (presented.open !== props.open) {
34+
setPresented({
35+
open: props.open,
36+
mounted: presented.mounted || props.open,
37+
session: props.open ? presented.session + 1 : presented.session,
38+
});
39+
}
40+
const afterClose = useRef<(() => void) | null>(null);
41+
const closed = () => {
42+
setPresented((current) => ({ ...current, mounted: false }));
43+
const then = afterClose.current;
44+
afterClose.current = null;
45+
then?.();
46+
};
47+
const close = (then?: () => void) => {
48+
afterClose.current = then ?? null;
49+
props.onClose();
50+
};
51+
if (!presented.mounted) return null;
52+
return (
53+
<FormSheet
54+
key={presented.session}
55+
isOpen={props.open}
56+
detents={formSheetDetents(0.6, 0.95)}
57+
prefersGrabberVisible={Platform.OS === "ios"}
58+
// The inspector's bar holds its actions, so the Duo needs no rail inside this sheet.
59+
prefersHorizontalBars
60+
preferredCornerRadius={Platform.OS === "android" ? 28 : undefined}
61+
nativeContainerStyle={containerStyle}
62+
onDismiss={closed}
63+
onNativeDismiss={() => {
64+
props.onClose();
65+
closed();
66+
}}
67+
>
68+
<InspectorSheetContext value={close}>
69+
<RoutedFormSheetContext value={false}>
70+
{/* The sheet starts below the status bar. */}
71+
<SafeAreaInsetsContext value={{ ...insets, top: 0 }}>
72+
<PaneContext value="inspector">
73+
{/* Android FormSheet does not bound flex children. */}
74+
<View
75+
collapsable={false}
76+
className={
77+
Platform.OS === "android" ? "absolute inset-0 bg-header pt-3" : "flex-1 bg-sheet"
78+
}
79+
>
80+
<RenderErrorBoundary
81+
renderFallback={(fallback) => (
82+
<RenderFailureView {...fallback} title="The inspector couldn't be displayed" />
83+
)}
84+
>
85+
{props.children}
86+
</RenderErrorBoundary>
87+
{Platform.OS === "android" ? (
88+
<View
89+
pointerEvents="none"
90+
className="absolute top-1 h-1 w-8 self-center rounded-full bg-header-foreground/40"
91+
/>
92+
) : null}
93+
</View>
94+
</PaneContext>
95+
</SafeAreaInsetsContext>
96+
</RoutedFormSheetContext>
97+
</InspectorSheetContext>
98+
</FormSheet>
99+
);
100+
}

‎apps/mobile/src/features/threads/ThreadRouteScreen.tsx‎

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -532,16 +532,6 @@ function ThreadRouteContent(
532532
const gitActionProgress = useGitActionProgress(gitActionProgressTarget);
533533

534534
const handleOpenGitInspector = () => {
535-
if (!fileInspector.supported) {
536-
if (selectedThread === null) {
537-
return;
538-
}
539-
navigation.navigate("GitOverview", {
540-
environmentId: String(selectedThread.environmentId),
541-
threadId: String(selectedThread.id),
542-
});
543-
return;
544-
}
545535
navigation.setParams({ inspector: undefined });
546536
setChosenInspectorMode("git");
547537
showInspector();
@@ -550,13 +540,6 @@ function ThreadRouteContent(
550540
if (selectedThread === null || selectedThreadCwd === null) {
551541
return;
552542
}
553-
if (!fileInspector.supported) {
554-
navigation.navigate("ThreadFiles", {
555-
environmentId: String(selectedThread.environmentId),
556-
threadId: String(selectedThread.id),
557-
});
558-
return;
559-
}
560543
navigation.setParams({ inspector: undefined });
561544
setChosenInspectorMode(props.renderInspector === undefined ? "files" : "route");
562545
showInspector();
@@ -577,33 +560,38 @@ function ThreadRouteContent(
577560
threadId: String(selectedThread.id),
578561
path: path.split("/").filter((segment) => segment.length > 0),
579562
};
580-
if (fileInspector.supported) {
581-
navigation.navigate("ThreadFile", params);
582-
return;
583-
}
584563
navigation.navigate("ThreadFile", params);
585564
};
586-
const safeAreaInsets = useSafeAreaInsets();
587-
const inspectorHeaderInset = Platform.OS === "ios" ? 0 : safeAreaInsets.top;
588565
const renderGitInspector = () => (
589-
<GitOverviewSheet
590-
headerInset={inspectorHeaderInset}
591-
presentation="inspector"
592-
route={{ params: { environmentId: environmentId!, threadId: threadId! } }}
593-
/>
566+
<InspectorHeaderInset>
567+
{(headerInset) => (
568+
<GitOverviewSheet
569+
headerInset={headerInset}
570+
presentation="inspector"
571+
route={{ params: { environmentId: environmentId!, threadId: threadId! } }}
572+
/>
573+
)}
574+
</InspectorHeaderInset>
594575
);
595576
const renderFilesInspector = () =>
596577
selectedThread !== null && selectedThreadCwd !== null ? (
597-
<ThreadFileNavigatorPane
598-
cwd={selectedThreadCwd}
599-
environmentId={selectedThread.environmentId}
600-
headerInset={inspectorHeaderInset}
601-
projectName={selectedThreadProject?.title ?? "Files"}
602-
selectedPath={null}
603-
onSelectFile={handleSelectInspectorFile}
604-
/>
578+
<InspectorHeaderInset>
579+
{(headerInset) => (
580+
<ThreadFileNavigatorPane
581+
cwd={selectedThreadCwd}
582+
environmentId={selectedThread.environmentId}
583+
headerInset={headerInset}
584+
projectName={selectedThreadProject?.title ?? "Files"}
585+
selectedPath={null}
586+
onSelectFile={handleSelectInspectorFile}
587+
/>
588+
)}
589+
</InspectorHeaderInset>
590+
) : null;
591+
const renderRouteInspector = () =>
592+
props.renderInspector ? (
593+
<InspectorHeaderInset>{props.renderInspector}</InspectorHeaderInset>
605594
) : null;
606-
const renderRouteInspector = () => props.renderInspector?.(inspectorHeaderInset);
607595
const renderPreviewInspector = () =>
608596
previewTarget && panes.auxiliaryPaneVisible ? (
609597
<ThreadInspectorPreview
@@ -765,9 +753,8 @@ function ThreadRouteContent(
765753
onPress: handleToggleInspector,
766754
}
767755
: undefined,
768-
onOpenFilesInspector:
769-
fileInspector.supported && selectedThreadCwd !== null ? handleOpenFilesInspector : undefined,
770-
onOpenGitInspector: fileInspector.supported ? handleOpenGitInspector : undefined,
756+
onOpenFilesInspector: selectedThreadCwd !== null ? handleOpenFilesInspector : undefined,
757+
onOpenGitInspector: handleOpenGitInspector,
771758
onMergeBack:
772759
mergeBackTargetThreadId !== null && mergeBackRun !== null
773760
? () => void handleMergeBack()
@@ -1081,6 +1068,12 @@ function ThreadRouteContent(
10811068
);
10821069
}
10831070

1071+
/** The inspector's top inset where it renders: under an Android column's status bar, not a sheet's. */
1072+
function InspectorHeaderInset(props: { readonly children: (headerInset: number) => ReactNode }) {
1073+
const insets = useSafeAreaInsets();
1074+
return props.children(Platform.OS === "ios" ? 0 : insets.top);
1075+
}
1076+
10841077
export function FullscreenThreadRouteScreen(
10851078
props: StaticScreenProps<{
10861079
readonly environmentId: string;

0 commit comments

Comments
 (0)