Skip to content

Commit e3eb026

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 4eb0927 commit e3eb026

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
@@ -547,16 +547,6 @@ function ThreadRouteContent(
547547
const gitActionProgress = useGitActionProgress(gitActionProgressTarget);
548548

549549
const handleOpenGitInspector = () => {
550-
if (!fileInspector.supported) {
551-
if (selectedThread === null) {
552-
return;
553-
}
554-
navigation.navigate("GitOverview", {
555-
environmentId: String(selectedThread.environmentId),
556-
threadId: String(selectedThread.id),
557-
});
558-
return;
559-
}
560550
navigation.setParams({ inspector: undefined });
561551
setChosenInspectorMode("git");
562552
showInspector();
@@ -565,13 +555,6 @@ function ThreadRouteContent(
565555
if (selectedThread === null || selectedThreadCwd === null) {
566556
return;
567557
}
568-
if (!fileInspector.supported) {
569-
navigation.navigate("ThreadFiles", {
570-
environmentId: String(selectedThread.environmentId),
571-
threadId: String(selectedThread.id),
572-
});
573-
return;
574-
}
575558
navigation.setParams({ inspector: undefined });
576559
setChosenInspectorMode(props.renderInspector === undefined ? "files" : "route");
577560
showInspector();
@@ -592,33 +575,38 @@ function ThreadRouteContent(
592575
threadId: String(selectedThread.id),
593576
path: path.split("/").filter((segment) => segment.length > 0),
594577
};
595-
if (fileInspector.supported) {
596-
navigation.navigate("ThreadFile", params);
597-
return;
598-
}
599578
navigation.navigate("ThreadFile", params);
600579
};
601-
const safeAreaInsets = useSafeAreaInsets();
602-
const inspectorHeaderInset = Platform.OS === "ios" ? 0 : safeAreaInsets.top;
603580
const renderGitInspector = () => (
604-
<GitOverviewSheet
605-
headerInset={inspectorHeaderInset}
606-
presentation="inspector"
607-
route={{ params: { environmentId: environmentId!, threadId: threadId! } }}
608-
/>
581+
<InspectorHeaderInset>
582+
{(headerInset) => (
583+
<GitOverviewSheet
584+
headerInset={headerInset}
585+
presentation="inspector"
586+
route={{ params: { environmentId: environmentId!, threadId: threadId! } }}
587+
/>
588+
)}
589+
</InspectorHeaderInset>
609590
);
610591
const renderFilesInspector = () =>
611592
selectedThread !== null && selectedThreadCwd !== null ? (
612-
<ThreadFileNavigatorPane
613-
cwd={selectedThreadCwd}
614-
environmentId={selectedThread.environmentId}
615-
headerInset={inspectorHeaderInset}
616-
projectName={selectedThreadProject?.title ?? "Files"}
617-
selectedPath={null}
618-
onSelectFile={handleSelectInspectorFile}
619-
/>
593+
<InspectorHeaderInset>
594+
{(headerInset) => (
595+
<ThreadFileNavigatorPane
596+
cwd={selectedThreadCwd}
597+
environmentId={selectedThread.environmentId}
598+
headerInset={headerInset}
599+
projectName={selectedThreadProject?.title ?? "Files"}
600+
selectedPath={null}
601+
onSelectFile={handleSelectInspectorFile}
602+
/>
603+
)}
604+
</InspectorHeaderInset>
605+
) : null;
606+
const renderRouteInspector = () =>
607+
props.renderInspector ? (
608+
<InspectorHeaderInset>{props.renderInspector}</InspectorHeaderInset>
620609
) : null;
621-
const renderRouteInspector = () => props.renderInspector?.(inspectorHeaderInset);
622610
const renderPreviewInspector = () =>
623611
previewTarget && panes.auxiliaryPaneVisible ? (
624612
<ThreadInspectorPreview
@@ -797,9 +785,8 @@ function ThreadRouteContent(
797785
onPress: handleToggleInspector,
798786
}
799787
: undefined,
800-
onOpenFilesInspector:
801-
fileInspector.supported && selectedThreadCwd !== null ? handleOpenFilesInspector : undefined,
802-
onOpenGitInspector: fileInspector.supported ? handleOpenGitInspector : undefined,
788+
onOpenFilesInspector: selectedThreadCwd !== null ? handleOpenFilesInspector : undefined,
789+
onOpenGitInspector: handleOpenGitInspector,
803790
onMergeBack:
804791
mergeBackTargetThreadId !== null && mergeBackRun !== null
805792
? () => void handleMergeBack()
@@ -1115,6 +1102,12 @@ function ThreadRouteContent(
11151102
);
11161103
}
11171104

1105+
/** The inspector's top inset where it renders: under an Android column's status bar, not a sheet's. */
1106+
function InspectorHeaderInset(props: { readonly children: (headerInset: number) => ReactNode }) {
1107+
const insets = useSafeAreaInsets();
1108+
return props.children(Platform.OS === "ios" ? 0 : insets.top);
1109+
}
1110+
11181111
export function FullscreenThreadRouteScreen(
11191112
props: StaticScreenProps<{
11201113
readonly environmentId: string;

0 commit comments

Comments
 (0)