Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AdaptiveWorkspaceLayout.tsx

1,166 lines47.2 KB

1import {
2 WorkspaceColumnsRendererContext,
3 WorkspacePresentationHostContext,
4} from "./workspace-presentation-context";
5import { useAndroidFloatingTabs } from "../settings/appearance/AppearancePreferencesProvider";
6import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context";
7import {
8 AdaptiveWorkspaceContext,
9 WorkspacePaneStateContext,
10 useAdaptiveWorkspaceLayout,
11 useWorkspacePaneState,
12 type AdaptiveWorkspaceActions,
13} from "./adaptive-workspace-context";
14import { threadSelectionDeferral } from "./deferred-navigation";
15import { uuidv4 } from "../../lib/uuid";
16import { EnvironmentId, ThreadId, type SidebarProjectGroupingMode } from "@t3tools/contracts";
17import { useAtomValue } from "@effect/atom-react";
18import { NavigationContext, NavigationRouteContext, useNavigation } from "@react-navigation/native";
19import {
20 use,
21 useEffect,
22 useEffectEvent,
23 useLayoutEffect,
24 useMemo,
25 useRef,
26 useState,
27 type ReactNode,
28} from "react";
29import {
30 BackHandler,
31 Keyboard,
32 Platform,
33 Pressable,
34 useWindowDimensions,
35 View,
36} from "react-native";
37import Animated, {
38 runOnJS,
39 useAnimatedStyle,
40 useDerivedValue,
41 useSharedValue,
42 withTiming,
43} from "react-native-reanimated";
44import { AsyncResult } from "effect/reactivity";
45​
46import {
47 deriveFileInspectorPaneLayout,
48 alignListPaneToHinge,
49 deriveLayout,
50 type VerticalHinge,
51 deriveWorkspacePaneLayout,
52 isPrimarySidebarPinned,
53 isWorkspaceListPath,
54 nativeInspectorColumnWidth,
55} from "../../lib/layout";
56import type { ThreadListFilters } from "../../persistence/mobile-preferences";
57import { appAtomRegistry } from "../../state/atom-registry";
58import { useProjects } from "../../state/entities";
59import { environmentThreadShells } from "../../state/threads";
60import { withKnownPullRequestSummary } from "../../state/use-thread-pr";
61import { mobilePreferencesAtom } from "../../state/preferences";
62import {
63 DEFAULT_MOBILE_PROJECT_GROUPING_SETTINGS,
64 resolveMobileProjectGroupingSettings,
65} from "../../state/project-grouping";
66import {
67 parseActiveThreadPath,
68 useHardwareKeyboardCommand,
69} from "../keyboard/hardwareKeyboardCommands";
70import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
71import { useEnabledNavigationTabs } from "./workspace/navigation-tabs";
72import { FLOATING_TABS, floatingTabsMetrics } from "./workspace/floating-workspace-tabs";
73import {
74 AndroidWorkspaceNavigation,
75 FloatingWorkspaceTabs,
76 ANDROID_WORKSPACE_RAIL_WIDTH,
77} from "./workspace/AndroidWorkspaceNavigation";
78import {
79 selectWorkspaceDetail,
80 type WorkspaceDetail,
81 type WorkspaceDetailSheet,
82} from "./workspace/workspace-detail-selection";
83import { startOpeningDetail } from "./workspace/useSelectWorkspaceDetail";
84import { useWorkspaceTabs } from "./workspace/WorkspaceTabsContext";
85import { HomeListOptionsProvider } from "../home/home-list-options";
86import { newTaskDestination } from "../threads/new-task-project-selection";
87import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderErrorBoundary";
88import { PaneContext } from "../../components/ui/Pane";
89import { WORKSPACE_PANE_TIMING } from "./workspace-pane-animation";
90import { WorkspaceInspectorPane } from "./workspace-inspector-pane";
91import { WorkspaceInspectorSheet } from "./workspace-inspector-sheet";
92import type { InspectorContent } from "./inspector-panes";
93import {
94 WorkspaceContentWidthContext,
95 WorkspaceSettledContentWidthContext,
96} from "./workspace-content-width";
97import {
98 NativeWorkspaceModeContext,
99 NativeWorkspaceInspectorContext,
100} from "../../native/v5-workspace-context";
101​
102import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
103import { AndroidHingeObserver } from "../../native/AndroidHingeObserver";
104import { WindowHingeContext } from "../../native/window-hinge-context";
105import { useAndroidWorkspaceRoot } from "./workspace/AndroidWorkspaceTabsProvider";
106import { dispatchRootStackReset, rootStackState } from "../../lib/root-stack-reset";
107import {
108 currentWorkspaceSelections,
109 workspaceSelectionCheck,
110} from "./workspace/workspace-selection-store";
111import {
112 workspaceTabColumns,
113 workspaceTabNavigationState,
114} from "./workspace/workspace-tab-navigation";
115import type { WorkspaceTab } from "./workspace/workspace-tabs-state";
116import { workspaceRoutesOf } from "./workspace-overlay-routes";
117import { SettingsWorkspaceLayout } from "../settings/SettingsWorkspaceLayout";
118import { WorkspaceThreadSidebar } from "./workspace/WorkspaceThreadSidebar";
119​
120export { useAdaptiveWorkspaceLayout, useWorkspacePaneState };
121​
122/**
123 * Shows these panes in the workspace's inspector while this screen is focused. Register on focus
124 * events because frozen blurred screens may never clean up.
125 */
126export function Inspector(props: {
127 readonly content: InspectorContent;
128 /** Opens the column the first time this key registers while its route stays on the stack. */
129 readonly revealKey?: string;
130}) {
131 const { registerWorkspaceInspector } = useAdaptiveWorkspaceLayout();
132 const navigation = use(NavigationContext);
133 const route = use(NavigationRouteContext);
134 const content: InspectorContent = {
135 ...props.content,
136 resetKeys: [route?.key, ...(props.content.resetKeys ?? [])],
137 panes: props.content.panes.map((pane) => ({
138 ...pane,
139 render: () => (
140 <NavigationContext.Provider value={navigation}>
141 <NavigationRouteContext.Provider value={route}>
142 {pane.render()}
143 </NavigationRouteContext.Provider>
144 </NavigationContext.Provider>
145 ),
146 })),
147 };
148 const focusedRef = useRef(false);
149 const deactivateRef = useRef<(() => void) | null>(null);
150​
151 const syncRegistration = useEffectEvent(() => {
152 if (!focusedRef.current) {
153 deactivateRef.current?.();
154 return;
155 }
156 deactivateRef.current = registerWorkspaceInspector(content, route?.key, props.revealKey);
157 });
158​
159 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Navigation focus events own the inspector registration lifetime.
160 useEffect(() => {
161 if (navigation === undefined) return;
162 const focus = () => {
163 if (focusedRef.current) return;
164 focusedRef.current = true;
165 syncRegistration();
166 };
167 const blur = () => {
168 focusedRef.current = false;
169 syncRegistration();
170 };
171 if (navigation.isFocused()) focus();
172 const unsubscribeFocus = navigation.addListener("focus", focus);
173 const unsubscribeBlur = navigation.addListener("blur", blur);
174 return () => {
175 unsubscribeFocus();
176 unsubscribeBlur();
177 focusedRef.current = false;
178 deactivateRef.current?.();
179 deactivateRef.current = null;
180 };
181 }, [navigation]);
182​
183 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Changed column content replaces the focused inspector registration.
184 useEffect(() => {
185 if (focusedRef.current) {
186 syncRegistration();
187 }
188 // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Changed column content replaces its existing native workspace registration.
189 }, [props.content, props.revealKey]);
190 return null;
192​
193/**
194 * Actions whose identities never change, so a pane toggle doesn't re-render every screen that
195 * holds one. Each call runs the latest render's handler.
196 */
197function useStableActions(actions: Required<AdaptiveWorkspaceActions>): AdaptiveWorkspaceActions {
198 const latest = useRef(actions);
199 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- points the stable actions at the handlers this commit rendered
200 useLayoutEffect(() => {
201 latest.current = actions;
202 });
203 const [stable] = useState((): AdaptiveWorkspaceActions => ({
204 startNewTask: () => latest.current.startNewTask(),
205 selectDetail: (detail, sheet) => latest.current.selectDetail(detail, sheet),
206 registerWorkspaceInspector: (content, routeKey, revealKey) =>
207 latest.current.registerWorkspaceInspector(content, routeKey, revealKey),
208 setPrimarySidebarSearchQuery: (query) => latest.current.setPrimarySidebarSearchQuery(query),
209 showInspector: () => latest.current.showInspector(),
210 toggleAuxiliaryPane: () => latest.current.toggleAuxiliaryPane(),
211 togglePrimarySidebar: () => latest.current.togglePrimarySidebar(),
212 revealPrimarySidebar: () => latest.current.revealPrimarySidebar(),
213 setPrimarySidebarVisible: (visible) => latest.current.setPrimarySidebarVisible(visible),
214 openWorkspaceTab: (tab, options) => latest.current.openWorkspaceTab(tab, options),
215 setAuxiliaryPaneWidth: (width) => latest.current.setAuxiliaryPaneWidth(width),
216 setNativeInspectorWidth: (width) => latest.current.setNativeInspectorWidth(width),
217 }));
218 return stable;
220​
221export function AdaptiveWorkspaceLayout(props: {
222 readonly children: ReactNode;
223 readonly pathname: string;
224 readonly workspaceRouteKey: string | undefined;
225 readonly workspaceRouteName: string | undefined;
226}) {
227 const preferencesResult = useAtomValue(mobilePreferencesAtom);
228 if (!AsyncResult.isSuccess(preferencesResult)) {
229 return AsyncResult.isFailure(preferencesResult) ? (
230 <AdaptiveWorkspaceLayoutContent
231 {...props}
232 projectGroupingMode={DEFAULT_MOBILE_PROJECT_GROUPING_SETTINGS.sidebarProjectGroupingMode}
233 />
234 ) : null;
235 }
236 const groupingSettings = resolveMobileProjectGroupingSettings(preferencesResult.value);
237 return (
238 <AdaptiveWorkspaceLayoutContent
239 {...props}
240 projectGroupingMode={groupingSettings.sidebarProjectGroupingMode}
241 savedThreadListFilters={preferencesResult.value.threadListFilters}
242 />
243 );
245​
246function AdaptiveWorkspaceLayoutContent(
247 props: {
248 readonly children: ReactNode;
249 readonly pathname: string;
250 readonly workspaceRouteKey: string | undefined;
251 readonly workspaceRouteName: string | undefined;
252 } & {
253 readonly projectGroupingMode: SidebarProjectGroupingMode;
254 readonly savedThreadListFilters?: ThreadListFilters | undefined;
255 },
256) {
257 const floatingTabsEnabled = useAndroidFloatingTabs();
258 const projectGroupingMode = props.projectGroupingMode;
259 const nativeWorkspace = use(NativeWorkspaceModeContext);
260 const usesPresentationHost = use(WorkspacePresentationHostContext);
261 const windowDimensions = useWindowDimensions();
262 const nativeMetrics = useNativeLayoutMetrics();
263 const { width: viewportWidth, height } = nativeMetrics ?? windowDimensions;
264 const pathname = props.pathname;
265 const workspace = useWorkspaceTabs();
266 // Settings and Usage occupy the workspace rather than a list/detail pair.
267 const androidSettingsOpen = useAndroidWorkspaceRoot()?.settingsOpen ?? false;
268 const safeAreaInsets = useSafeAreaInsets();
269 const workspacePage =
270 Platform.OS === "android" && (androidSettingsOpen || workspace?.state.selectedTab === "usage");
271 const navigation = useNavigation();
272 const [primarySidebarPreferredVisible, setPrimarySidebarPreferredVisible] = useState(true);
273 const [fileInspectorPreferredVisible, setFileInspectorPreferredVisible] = useState(true);
274 const [nativeInspectorWidthFraction, setNativeInspectorWidthFraction] = useState(0.4);
275 const horizontalSafeArea =
276 (nativeMetrics?.safeArea.left ?? 0) + (nativeMetrics?.safeArea.right ?? 0);
277 const inspectorWidthFor = (fraction: number) =>
278 nativeInspectorColumnWidth({ viewportWidth, horizontalSafeArea, fraction });
279 const nativeInspectorWidth = inspectorWidthFor(nativeInspectorWidthFraction);
280 const [fileInspectorPreferredWidth, setFileInspectorPreferredWidth] = useState<number | null>(
281 null,
282 );
283 const [primarySidebarSearchQuery, setPrimarySidebarSearchQuery] = useState("");
284 const [railOverlay, setRailOverlay] = useState(false);
285 // The compiler can't memoize these derivations: they stay live across later hook calls. Fresh
286 // objects here change the workspace context on every render, so every workspace screen
287 // re-renders on any layout state change, and the inspector registration then loops: each
288 // re-register re-renders its screen, which hands over a new inspector renderer.
289 const baseLayout = useMemo(
290 () => deriveLayout({ width: viewportWidth, height, nativeMetrics, nativeWorkspace }),
291 [height, viewportWidth, nativeMetrics, nativeWorkspace],
292 );
293 // The overlay sidebar closes when a page opens from it, and stays open on a list or on the
294 // page a tab switch opened (`keepOpenFor`, set by that switch).
295 const [overlaySidebar, setOverlaySidebar] = useState({
296 active: baseLayout.variant === "medium",
297 pathname,
298 visible: isWorkspaceListPath(pathname),
299 keepOpenFor: null as string | null,
300 });
301 if (
302 overlaySidebar.active !== (baseLayout.variant === "medium") ||
303 (overlaySidebar.active && overlaySidebar.pathname !== pathname)
304 ) {
305 setOverlaySidebar({
306 active: baseLayout.variant === "medium",
307 pathname,
308 visible:
309 isWorkspaceListPath(pathname) ||
310 (overlaySidebar.keepOpenFor !== null &&
311 overlaySidebar.keepOpenFor === props.workspaceRouteKey),
312 keepOpenFor: null,
313 });
314 }
315 const preferredSidebarVisible =
316 baseLayout.variant === "medium" ? overlaySidebar.visible : primarySidebarPreferredVisible;
317 const primarySidebarPinned = isPrimarySidebarPinned({
318 pathname,
319 nativeWorkspace,
320 usesSplitView: baseLayout.usesSplitView,
321 });
322 const showPrimarySidebar = !workspacePage && (primarySidebarPinned || preferredSidebarVisible);
323 // Medium windows float the sidebar over a page; beside a list it keeps its room.
324 const sidebarFloats =
325 baseLayout.variant === "medium" &&
326 (nativeWorkspace || (!primarySidebarPinned && !workspacePage));
327 const shouldRenderNavigationRail =
328 Platform.OS === "android" && baseLayout.usesSplitView && !floatingTabsEnabled;
329 const enabledTabs = useEnabledNavigationTabs();
330 const { scale, fabSize } = useAndroidControlSizing();
331 const floatingTabs = floatingTabsMetrics(enabledTabs.length + 1, scale, fabSize);
332 // The rail stays whether or not the sidebar shows; only the list pane comes and goes.
333 const navigationRailWidth = shouldRenderNavigationRail ? ANDROID_WORKSPACE_RAIL_WIDTH : 0;
334 const [hinge, setHinge] = useState<VerticalHinge | null>(null);
335 const [windowHinge, setWindowHinge] = useState<VerticalHinge | null>(null);
336 const handleHingeChange = (next: VerticalHinge | null, nextWindow: VerticalHinge | null) => {
337 setHinge(next);
338 setWindowHinge(nextWindow);
339 };
340 const layout = useMemo(() => {
341 const aligned = alignListPaneToHinge({
342 layout: baseLayout,
343 hinge,
344 viewportWidth,
345 leadingWidth: navigationRailWidth,
346 });
347 if (
348 !floatingTabsEnabled ||
349 !aligned.usesSplitView ||
350 aligned.listPaneGap !== undefined ||
351 aligned.listPaneWidth === null ||
352 aligned.listPaneWidth >= floatingTabs.row ||
353 viewportWidth - floatingTabs.row < 320
354 )
355 return aligned;
356 return { ...aligned, listPaneWidth: floatingTabs.row };
357 }, [
358 baseLayout,
359 hinge,
360 navigationRailWidth,
361 viewportWidth,
362 floatingTabs.row,
363 floatingTabsEnabled,
364 ]);
365 // The rail keeps its room even while the sidebar floats; only the list pane overlays the page.
366 const width = viewportWidth - navigationRailWidth;
367 // The sidebar stays mounted under a workspace page, so its list is ready on the way back.
368 const shouldRenderPrimarySidebar = layout.usesSplitView;
369 const fileInspector = useMemo(
370 () =>
371 deriveFileInspectorPaneLayout({
372 layout,
373 viewportWidth: width,
374 preferredWidth: fileInspectorPreferredWidth ?? undefined,
375 reservedLeadingWidth:
376 shouldRenderPrimarySidebar && showPrimarySidebar && !sidebarFloats
377 ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
378 : 0,
379 }),
380 [
381 fileInspectorPreferredWidth,
382 layout,
383 showPrimarySidebar,
384 shouldRenderPrimarySidebar,
385 sidebarFloats,
386 width,
387 ],
388 );
389 const [workspaceInspector, setWorkspaceInspector] = useState<{
390 readonly content: InspectorContent;
391 readonly active: boolean;
392 readonly routeKey: string | undefined;
393 } | null>(null);
394 // Without a column the inspector is a sheet, opened only on request for the route on top, and
395 // shown again when that route returns to the top.
396 const [inspectorSheetRoute, setInspectorSheetRoute] = useState<string | null>(null);
397 const inspectorSheetOpen =
398 !fileInspector.supported &&
399 !workspacePage &&
400 inspectorSheetRoute !== null &&
401 workspaceInspector?.active === true &&
402 workspaceInspector.routeKey === inspectorSheetRoute;
403 const inspectorActive = workspaceInspector?.active ?? false;
404 const panes = useMemo(
405 () =>
406 deriveWorkspacePaneLayout({
407 layout,
408 viewportWidth: width,
409 horizontalSafeArea,
410 nativeWorkspace,
411 primarySidebarFloats: sidebarFloats,
412 primarySidebarPreferredVisible: showPrimarySidebar,
413 // Only a column a screen fills makes room, so a stale preference can't hide the sidebar.
414 auxiliaryPanePreferredVisible:
415 !workspacePage && inspectorActive && fileInspectorPreferredVisible,
416 auxiliaryPanePreferredWidth: fileInspectorPreferredWidth ?? undefined,
417 nativeInspectorWidth,
418 }),
419 [
420 nativeInspectorWidth,
421 horizontalSafeArea,
422 fileInspectorPreferredVisible,
423 fileInspectorPreferredWidth,
424 inspectorActive,
425 layout,
426 nativeWorkspace,
427 showPrimarySidebar,
428 sidebarFloats,
429 width,
430 workspacePage,
431 ],
432 );
433 // Routes still on the stack remember their reveal, so going back to one keeps the user's choice.
434 const revealedInspectors = useRef<ReadonlyMap<string, string>>(new Map());
435 const workspaceInspectorOwner = useRef<symbol | null>(null);
436 const registerWorkspaceInspector = (
437 content: InspectorContent,
438 routeKey: string | undefined,
439 revealKey?: string,
440 ) => {
441 const owner = Symbol("workspace-inspector");
442 workspaceInspectorOwner.current = owner;
443 setWorkspaceInspector({ content, active: true, routeKey });
444 if (
445 routeKey !== undefined &&
446 revealKey !== undefined &&
447 revealedInspectors.current.get(routeKey) !== revealKey
448 ) {
449 const state = rootStackState(navigation);
450 const live = new Set(state?.routes.slice(0, state.index + 1).map((route) => route.key));
451 revealedInspectors.current = new Map(
452 [...revealedInspectors.current, [routeKey, revealKey] as const].filter(
453 ([key]) => live.has(key) || key === routeKey,
454 ),
455 );
456 setFileInspectorPreferredVisible(true);
457 }
458​
459 return () => {
460 // Outgoing screens deactivate after incoming registration; only the current owner may deactivate.
461 if (workspaceInspectorOwner.current !== owner) {
462 return;
463 }
464 setWorkspaceInspector((current) => (current === null ? null : { ...current, active: false }));
465 };
466 };
467 const handleWorkspaceInspectorClosed = () => {
468 setWorkspaceInspector((current) => (current !== null && !current.active ? null : current));
469 };
470 const setPrimarySidebarVisible = (visible: boolean) => {
471 if (layout.variant === "medium") {
472 setOverlaySidebar((current) => ({ ...current, visible }));
473 } else {
474 setPrimarySidebarPreferredVisible(visible);
475 }
476 };
477 const togglePrimarySidebar = () => {
478 if (primarySidebarPinned) {
479 return;
480 }
481 if (!panes.primarySidebarVisible && panes.primarySidebarSuppressedByAuxiliary) {
482 setFileInspectorPreferredVisible(false);
483 setPrimarySidebarPreferredVisible(true);
484 return;
485 }
486 setPrimarySidebarVisible(!preferredSidebarVisible);
487 };
488 const revealPrimarySidebar = () => {
489 if (panes.primarySidebarSuppressedByAuxiliary) {
490 setFileInspectorPreferredVisible(false);
491 }
492 setPrimarySidebarVisible(true);
493 };
494 const handleToggleSidebarCommand = () => {
495 togglePrimarySidebar();
496 return true;
497 };
498 const sidebarCommands = primarySidebarPinned ? [] : (["toggleSidebar"] as const);
499 useHardwareKeyboardCommand(sidebarCommands, handleToggleSidebarCommand);
500 // Resizing into a column closes the sheet without this, so the inspector moves into the column.
501 const dismissInspectorSheet = () => {
502 setFileInspectorPreferredVisible(false);
503 setInspectorSheetRoute(null);
504 };
505 const showInspector = () => {
506 setFileInspectorPreferredVisible(true);
507 if (fileInspector.supported) {
508 setInspectorSheetRoute(null);
509 return;
510 }
511 const state = rootStackState(navigation);
512 const top = workspaceRoutesOf(state?.routes.slice(0, state.index + 1) ?? []).workspace.at(-1);
513 setInspectorSheetRoute(top?.key ?? null);
514 };
515 const handleOpenFilesCommand = () => {
516 const activeThread = parseActiveThreadPath(pathname);
517 if (!layout.usesSplitView || !fileInspector.supported || activeThread === null) {
518 return false;
519 }
520 showInspector();
521 if (props.workspaceRouteName === "ThreadFiles" || props.workspaceRouteName === "ThreadFile") {
522 return true;
523 }
524 navigation.navigate("ThreadFiles", activeThread);
525 return true;
526 };
527 useHardwareKeyboardCommand("files", handleOpenFilesCommand);
528 const toggleAuxiliaryPane = () => {
529 if (fileInspector.supported) {
530 setFileInspectorPreferredVisible((current) => !current);
531 setInspectorSheetRoute(null);
532 } else if (inspectorSheetOpen) dismissInspectorSheet();
533 else showInspector();
534 };
535 /**
536 * The one way to open a workspace tab: replaces the workspace with the tab's list and, when the
537 * window has columns, the page it last showed, keeping any sheet on top. An overlay sidebar
538 * stays open over that page.
539 */
540 const openWorkspaceTab = (
541 tab: WorkspaceTab | "settings",
542 options?: { readonly columns?: boolean },
543 ) => {
544 const state = rootStackState(navigation);
545 if (!state) return;
546 const { workspace, overlays } = workspaceRoutesOf(state.routes.slice(0, state.index + 1));
547 const next = workspaceTabNavigationState(
548 { ...state, routes: workspace },
549 tab,
550 currentWorkspaceSelections(),
551 {
552 columns: workspaceTabColumns(Platform.OS, tab, options?.columns ?? layout.usesSplitView),
553 check: workspaceSelectionCheck,
554 overlays,
555 seedPullRequest: withKnownPullRequestSummary,
556 },
557 );
558 if (layout.variant === "medium") {
559 const opened = next.routes.at(-1 - overlays.length)?.key ?? null;
560 setOverlaySidebar((current) => ({ ...current, visible: true, keepOpenFor: opened }));
561 }
562 dispatchRootStackReset(navigation, state, next);
563 };
564 const handleOpenSettings = () => openWorkspaceTab("settings");
565​
566 /** The one way to show a page in the detail column; see `selectWorkspaceDetail`. */
567 function handleSelectDetail(detail: WorkspaceDetail, sheet?: WorkspaceDetailSheet) {
568 threadSelectionDeferral.run(() => {
569 if (Platform.OS === "android") Keyboard.dismiss();
570 setFileInspectorPreferredVisible(false);
571 setInspectorSheetRoute(null);
572 if (layout.variant === "medium") setPrimarySidebarVisible(false);
573 workspace?.dispatch({
574 type: "select",
575 tab: detail.name === "Thread" ? "threads" : "pullRequests",
576 });
577 startOpeningDetail(detail);
578 navigation.dispatch(selectWorkspaceDetail(detail, sheet));
579 });
580 }
581 const handleSelectThreadRoute = (params: ReactNavigation.RootParamList["Thread"]) =>
582 handleSelectDetail({ name: "Thread", params });
583​
584 const projects = useProjects();
585 const compactAndroidSettings =
586 Platform.OS === "android" && androidSettingsOpen && !layout.usesSplitView;
587 // Reads the open page when pressed, so the layout context doesn't change on every navigation.
588 const handleStartNewTask = () => {
589 const state = rootStackState(navigation);
590 const currentRoute = workspaceRoutesOf(
591 state?.routes.slice(0, state.index + 1) ?? [],
592 ).workspace.at(-1);
593 const params =
594 currentRoute?.name === "Thread"
595 ? (currentRoute.params as ReactNavigation.RootParamList["Thread"])
596 : undefined;
597 const first = (value: string | string[] | undefined) =>
598 Array.isArray(value) ? value[0] : value;
599 const environmentId = first(params?.environmentId);
600 const threadId = first(params?.threadId);
601 // The full index, not the sidebar list: subagent and archived threads are current threads too.
602 const projectId =
603 environmentId && threadId
604 ? appAtomRegistry
605 .get(
606 environmentThreadShells.environmentThreadIndexAtom(EnvironmentId.make(environmentId)),
607 )
608 .get(ThreadId.make(threadId))?.projectId
609 : undefined;
610 const preferences = appAtomRegistry.get(mobilePreferencesAtom);
611 const saved = AsyncResult.isSuccess(preferences) ? preferences.value : undefined;
612 handleSelectThreadRoute(
613 newTaskDestination({
614 projects,
615 requestId: uuidv4(),
616 useLastProject: saved?.useLastProjectForNewThreads,
617 currentProject: environmentId && projectId ? { environmentId, projectId } : undefined,
618 lastProject: saved?.lastThreadProject,
619 }),
620 );
621 };
622​
623 useHardwareKeyboardCommand("newTask", () => {
624 handleStartNewTask();
625 return true;
626 });
627​
628 const inspectorColumnTargetWidth = panes.auxiliaryPaneVisible
629 ? (panes.auxiliaryPaneWidth ?? 0)
630 : 0;
631 // Android's split content is a rounded card: keep it off the screen edge like the list card.
632 const contentEndGap = Platform.OS === "android" && layout.usesSplitView ? 4 : 0;
633 // Android's split is one strip: a sidebar slot of fixed width, then the detail pane. The
634 // sidebar never resizes; both slide by one offset, so together they always fill the width.
635 const stripSidebar =
636 Platform.OS === "android" &&
637 layout.usesSplitView &&
638 layout.listPaneWidth !== null &&
639 !workspacePage &&
640 !sidebarFloats;
641 const sidebarSlotWidth = (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0);
642 // The pane takes its new width in the commit that starts the sidebar moving, so it rewraps as
643 // the strip starts to slide rather than after it lands.
644 const contentSpansSidebar = stripSidebar && !panes.primarySidebarVisible;
645 const contentTargetWidth = !layout.usesSplitView
646 ? null
647 : Math.max(
648 0,
649 (contentSpansSidebar ? width : panes.contentPaneWidth) -
650 inspectorColumnTargetWidth -
651 contentEndGap,
652 );
653 // A workspace page (Usage) lays out at this width even while hidden behind another tab, so
654 // opening it widens nothing it measured.
655 const workspacePageWidth = !layout.usesSplitView
656 ? null
657 : workspacePage
658 ? contentTargetWidth
659 : Math.max(
660 0,
661 viewportWidth -
662 (shouldRenderNavigationRail ? ANDROID_WORKSPACE_RAIL_WIDTH : 0) -
663 contentEndGap,
664 );
665 const [listPaneSizing, setListPaneSizing] = useState({
666 viewportWidth,
667 workspacePage,
668 sidebarVisible: panes.primarySidebarVisible,
669 listPaneTarget: layout.listPaneWidth,
670 listPaneFloor: layout.listPaneWidth,
671 listPaneCeiling: layout.listPaneWidth,
672 revision: 0,
673 });
674 if (
675 Platform.OS === "android" &&
676 (listPaneSizing.viewportWidth !== viewportWidth ||
677 listPaneSizing.workspacePage !== workspacePage ||
678 listPaneSizing.sidebarVisible !== panes.primarySidebarVisible ||
679 listPaneSizing.listPaneTarget !== layout.listPaneWidth)
680 ) {
681 // A book-posture hinge resizes the visible list pane instead of revealing it.
682 const resizingSidebar =
683 listPaneSizing.viewportWidth === viewportWidth &&
684 listPaneSizing.workspacePage === workspacePage &&
685 listPaneSizing.sidebarVisible &&
686 panes.primarySidebarVisible &&
687 listPaneSizing.listPaneTarget !== layout.listPaneWidth;
688 setListPaneSizing({
689 viewportWidth,
690 workspacePage,
691 sidebarVisible: panes.primarySidebarVisible,
692 listPaneTarget: layout.listPaneWidth,
693 // Retargets widen the list-width span because the animated hinge edge may still be inside it.
694 listPaneFloor: resizingSidebar
695 ? Math.min(listPaneSizing.listPaneFloor ?? 0, layout.listPaneWidth ?? 0)
696 : layout.listPaneWidth,
697 listPaneCeiling: resizingSidebar
698 ? Math.max(listPaneSizing.listPaneCeiling ?? 0, layout.listPaneWidth ?? 0)
699 : layout.listPaneWidth,
700 revision: listPaneSizing.revision + 1,
701 });
702 }
703 const settleListPane = (revision: number) => {
704 setListPaneSizing((current) =>
705 current.revision !== revision ||
706 (current.listPaneFloor === current.listPaneTarget &&
707 current.listPaneCeiling === current.listPaneTarget)
708 ? current
709 : {
710 ...current,
711 listPaneFloor: current.listPaneTarget,
712 listPaneCeiling: current.listPaneTarget,
713 },
714 );
715 };
716 const listPaneFloor = listPaneSizing.listPaneFloor ?? 0;
717 const listPaneCeiling = listPaneSizing.listPaneCeiling ?? 0;
718 const listPaneRevision = listPaneSizing.revision;
719 // Android lays the content out at its new width as soon as a pane toggles, then holds it
720 // against the edge that stays put while the other one slides, so nothing reflows after the
721 // panes land. A sliding sidebar uncovers the strip it is about to fill, or covers the content
722 // until it is gone.
723 const contentLeftTarget = sidebarFloats
724 ? navigationRailWidth
725 : navigationRailWidth +
726 (shouldRenderPrimarySidebar && !workspacePage && panes.primarySidebarVisible
727 ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
728 : 0);
729 const [contentAnchor, setContentAnchor] = useState({
730 viewportWidth,
731 left: contentLeftTarget,
732 inspector: inspectorColumnTargetWidth,
733 end: false,
734 });
735 if (
736 Platform.OS === "android" &&
737 (contentAnchor.viewportWidth !== viewportWidth ||
738 contentAnchor.left !== contentLeftTarget ||
739 contentAnchor.inspector !== inspectorColumnTargetWidth)
740 ) {
741 setContentAnchor({
742 viewportWidth,
743 left: contentLeftTarget,
744 inspector: inspectorColumnTargetWidth,
745 end:
746 contentAnchor.viewportWidth === viewportWidth &&
747 contentAnchor.inspector === inspectorColumnTargetWidth,
748 });
749 }
750​
751 const renderedSidebarWidth = useSharedValue(
752 panes.primarySidebarVisible ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0) : 0,
753 );
754 const renderedRailWidth = useSharedValue(navigationRailWidth);
755 const leavingWorkspacePage = useRef(false);
756 // The slide starts after the commit that lays the pane out, not in the press handler: Reanimated
757 // commits the shadow tree every frame, and that starves a large React commit until it stops.
758 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- animates the Reanimated rail and sidebar width shared values toward the layout's targets
759 useEffect(() => {
760 if (nativeWorkspace) return;
761 renderedRailWidth.set(withTiming(navigationRailWidth, WORKSPACE_PANE_TIMING));
762 // A workspace page hides the sidebar through React instead, in the same commit that mounts
763 // the page. Animating it here would hide it a few frames before the page appears.
764 if (workspacePage) {
765 leavingWorkspacePage.current = true;
766 return;
767 }
768 const snap = leavingWorkspacePage.current;
769 leavingWorkspacePage.current = false;
770 const targetWidth = panes.primarySidebarVisible
771 ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
772 : 0;
773 // The content beside it already took its final width when the page closed.
774 renderedSidebarWidth.set(
775 withTiming(targetWidth, snap ? { duration: 0 } : WORKSPACE_PANE_TIMING, (finished) => {
776 // Only a hinge resize widens the list's span; a toggle has nothing to settle.
777 if (finished && Platform.OS === "android" && listPaneFloor !== listPaneCeiling) {
778 runOnJS(settleListPane)(listPaneRevision);
779 }
780 }),
781 );
782 }, [
783 nativeWorkspace,
784 navigationRailWidth,
785 layout.listPaneWidth,
786 layout.listPaneGap,
787 panes.primarySidebarVisible,
788 renderedSidebarWidth,
789 renderedRailWidth,
790 settleListPane,
791 listPaneFloor,
792 listPaneCeiling,
793 listPaneRevision,
794 workspacePage,
795 ]);
796 const railAnimatedStyle = useAnimatedStyle(() => ({ width: renderedRailWidth.value }));
797 const floatingSidebarAnimatedStyle = useAnimatedStyle(() => ({
798 left: sidebarFloats ? renderedRailWidth.value : 0,
799 }));
800 const floatingSidebarOpen = sidebarFloats && panes.primarySidebarVisible;
801 // Its own value, so a sidebar that was beside a list doesn't dim the page as it leaves.
802 const scrimOpacity = useSharedValue(0);
803 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- animates the Reanimated scrim with the floating sidebar
804 useEffect(() => {
805 scrimOpacity.set(withTiming(floatingSidebarOpen ? 0.32 : 0, WORKSPACE_PANE_TIMING));
806 }, [floatingSidebarOpen, scrimOpacity]);
807 const scrimAnimatedStyle = useAnimatedStyle(() => ({ opacity: scrimOpacity.value }));
808 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Back closes a floating sidebar before it leaves the page
809 useEffect(() => {
810 if (!floatingSidebarOpen || nativeWorkspace) return;
811 const subscription = BackHandler.addEventListener("hardwareBackPress", () => {
812 // A sheet or modal over the workspace takes Back first.
813 const state = rootStackState(navigation);
814 if (state && workspaceRoutesOf(state.routes.slice(0, state.index + 1)).overlays.length > 0) {
815 return false;
816 }
817 setPrimarySidebarVisible(false);
818 return true;
819 });
820 return () => subscription.remove();
821 }, [floatingSidebarOpen, nativeWorkspace, navigation, setPrimarySidebarVisible]);
822 // Showing or hiding the sidebar clips a fixed-width list. A hinge resize instead tracks the
823 // animated edge, so the header actions slide with it rather than jumping or being covered.
824 const listPaneGap = layout.listPaneGap ?? 0;
825 const listPaneAnimatedStyle = useAnimatedStyle(() => ({
826 width: Math.min(
827 listPaneCeiling,
828 Math.max(
829 listPaneFloor,
830 (stripSidebar ? sidebarSlotWidth : renderedSidebarWidth.value) - listPaneGap,
831 ),
832 ),
833 }));
834 // How far the strip has slid: 0 with the sidebar shown, minus its width with it gone.
835 const stripOffset = useDerivedValue(() =>
836 stripSidebar ? renderedSidebarWidth.value - sidebarSlotWidth : 0,
837 );
838 const sidebarAnimatedStyle = useAnimatedStyle(() => ({
839 // Fading a UIKit glass ancestor can leave remounted header effects missing.
840 opacity:
841 stripSidebar || Platform.OS === "ios" || floatingTabsEnabled
842 ? 1
843 : Math.min(1, renderedSidebarWidth.value / 80),
844 width: stripSidebar ? sidebarSlotWidth : renderedSidebarWidth.value,
845 flexShrink: stripSidebar ? 0 : 1,
846 transform: [{ translateX: stripOffset.value }],
847 }));
848​
849 // Clip the navigator at its settled width so native headers and markdown reflow only once per pane toggle.
850 const renderedInspectorWidth = useSharedValue(inspectorColumnTargetWidth);
851 const renderedContentWidth = useDerivedValue(() =>
852 Math.max(
853 0,
854 viewportWidth -
855 renderedRailWidth.value -
856 (workspacePage || sidebarFloats ? 0 : renderedSidebarWidth.value) -
857 renderedInspectorWidth.value,
858 ),
859 );
860 // Android can resize the native row before React removes its split panes on a fold.
861 const androidSplit = Platform.OS === "android" && layout.usesSplitView;
862 // In the strip the column itself slides with the sidebar: Android only delivers touches inside a
863 // parent's bounds, so content may not slide out of its column. Every branch sets every key:
864 // Reanimated keeps a key a branch drops, so a fold mid-slide would leave the column shifted.
865 const androidContentSlotStyle = useAnimatedStyle(() =>
866 !androidSplit
867 ? { width: "100%" as const, marginRight: 0, transform: [{ translateX: 0 }] }
868 : stripSidebar
869 ? {
870 // Wide enough for the pane at either width; the margin gives the sidebar's share
871 // back to the row, so a column after it stays put while the strip slides.
872 width: Math.max(
873 0,
874 viewportWidth - renderedRailWidth.value - renderedInspectorWidth.value,
875 ),
876 marginRight: -sidebarSlotWidth,
877 transform: [{ translateX: stripOffset.value }],
878 }
879 : { width: renderedContentWidth.value, marginRight: 0, transform: [{ translateX: 0 }] },
880 );
881 // While the sidebar animates, clip the settled navigator instead of reflowing its text every frame.
882 // In the strip it lifts entirely: the content outgrows its column, and a cap that follows
883 // React's width would clip the wider layout for the frame it lands.
884 const androidNavigatorLimit = useAnimatedStyle(() => ({
885 maxWidth: stripSidebar
886 ? viewportWidth
887 : androidSplit &&
888 contentTargetWidth !== null &&
889 renderedContentWidth.value < contentTargetWidth
890 ? contentTargetWidth
891 : ("100%" as const),
892 }));
893​
894 // Rotating flips the overlay; until the new size reaches JS, predict the reset above.
895 const sidebarOverRotates =
896 nativeWorkspace && nativeMetrics?.hasHinge === true && layout.usesSplitView;
897 // The current orientation's panes already account for an inspector that needs the sidebar's room.
898 const sidebarInLandscape =
899 baseLayout.variant === "medium"
900 ? primarySidebarPinned || primarySidebarPreferredVisible
901 : panes.primarySidebarVisible;
902 const sidebarInPortrait =
903 primarySidebarPinned ||
904 (baseLayout.variant === "medium" ? overlaySidebar.visible : isWorkspaceListPath(pathname));
905 const sidebarByOrientation = useMemo(
906 () =>
907 sidebarOverRotates ? { landscape: sidebarInLandscape, portrait: sidebarInPortrait } : null,
908 [sidebarInLandscape, sidebarInPortrait, sidebarOverRotates],
909 );
910​
911 const actions = useStableActions({
912 startNewTask: handleStartNewTask,
913 selectDetail: handleSelectDetail,
914 registerWorkspaceInspector,
915 setPrimarySidebarSearchQuery,
916 showInspector,
917 toggleAuxiliaryPane,
918 togglePrimarySidebar,
919 revealPrimarySidebar,
920 setPrimarySidebarVisible,
921 openWorkspaceTab,
922 setAuxiliaryPaneWidth: setFileInspectorPreferredWidth,
923 setNativeInspectorWidth: (width: number) =>
924 setNativeInspectorWidthFraction(inspectorWidthFor(width / viewportWidth) / viewportWidth),
925 });
926 const contextValue = useMemo(
927 () => ({ ...actions, layout, nativeInspectorWidth, workspacePageWidth }),
928 [actions, layout, nativeInspectorWidth, workspacePageWidth],
929 );
930 const sidebarToggleable = layout.usesSplitView && !primarySidebarPinned && !workspacePage;
931 const paneState = useMemo(
932 () => ({
933 panes,
934 fileInspector,
935 primarySidebarSearchQuery,
936 sidebarToggleable,
937 sidebarByOrientation,
938 }),
939 [panes, fileInspector, primarySidebarSearchQuery, sidebarToggleable, sidebarByOrientation],
940 );
941​
942 const inspectorSheet = (
943 <WorkspaceInspectorSheet
944 open={inspectorSheetOpen}
945 onClose={dismissInspectorSheet}
946 content={workspaceInspector?.content}
947 />
948 );
949 if (nativeWorkspace) {
950 return (
951 <HomeListOptionsProvider
952 projectGroupingMode={projectGroupingMode}
953 savedFilters={props.savedThreadListFilters}
954 >
955 <AdaptiveWorkspaceContext value={contextValue}>
956 <WorkspacePaneStateContext value={paneState}>
957 <NativeWorkspaceInspectorContext
958 value={{
959 // Without a column the sheet shows it; the hidden native column must not mount it too.
960 content: fileInspector.supported ? workspaceInspector?.content : undefined,
961 visible: inspectorColumnTargetWidth > 0,
962 }}
963 >
964 {props.children}
965 {inspectorSheet}
966 </NativeWorkspaceInspectorContext>
967 </WorkspacePaneStateContext>
968 </AdaptiveWorkspaceContext>
969 </HomeListOptionsProvider>
970 );
971 }
972 const renderColumns = (children: ReactNode, sidebar?: ReactNode) => (
973 <View
974 testID="adaptive-workspace-layout"
975 className={Platform.OS === "android" ? "flex-1 flex-row bg-header" : "flex-1 flex-row"}
976 >
977 <AndroidHingeObserver onChange={handleHingeChange} />
978 {shouldRenderNavigationRail ? (
979 <Animated.View className="shrink self-stretch" style={railAnimatedStyle} />
980 ) : null}
981 {shouldRenderPrimarySidebar && layout.listPaneWidth !== null ? (
982 <Animated.View
983 className="self-stretch overflow-hidden android:shrink"
984 accessibilityElementsHidden={workspacePage || !panes.primarySidebarVisible}
985 collapsable={false}
986 importantForAccessibility={
987 !workspacePage && panes.primarySidebarVisible ? "auto" : "no-hide-descendants"
988 }
989 pointerEvents={!workspacePage && panes.primarySidebarVisible ? "auto" : "none"}
990 // Under a workspace page the sidebar leaves the row but keeps its size, so its
991 // lists never lay out at zero size and are ready, unchanged, on the way back. The
992 // content pane, laid out after it, covers it, in the same mount as the page.
993 style={[
994 workspacePage ? { position: "absolute", top: 0, bottom: 0, left: 0 } : null,
995 sidebarFloats
996 ? { position: "absolute", top: 0, bottom: 0, zIndex: 2, elevation: 8 }
997 : null,
998 floatingSidebarAnimatedStyle,
999 sidebarAnimatedStyle,
1000 ]}
1002 <Animated.View className="flex-1" style={listPaneAnimatedStyle}>
1003 <PaneContext value="sidebar">
1004 <RenderErrorBoundary
1005 renderFallback={(fallback) => (
1006 <RenderFailureView
1007 {...fallback}
1008 title="The sidebar couldn't be displayed"
1009 exit={{ label: "Open settings", onPress: handleOpenSettings }}
1010 />
1011 )}
1013 {/* Without a sidebar route (iPadOS before 26) the columns draw the thread list. */}
1014 {sidebar ?? <WorkspaceThreadSidebar />}
1015 </RenderErrorBoundary>
1016 </PaneContext>
1017 {/* Keep the pill under the content throughout the sidebar's clipping animation. */}
1018 {floatingTabsEnabled && !workspacePage ? (
1019 <FloatingWorkspaceTabs
1020 paneWidth={layout.listPaneWidth}
1021 onNewThread={handleStartNewTask}
1022 onSelect={revealPrimarySidebar}
1023 />
1024 ) : null}
1025 </Animated.View>
1026 </Animated.View>
1027 ) : null}
1028 <Animated.View
1029 className={
1030 Platform.OS === "android"
1031 ? "max-w-full shrink-0 overflow-hidden bg-header"
1032 : "flex-1 overflow-hidden bg-screen"
1034 style={Platform.OS === "android" ? androidContentSlotStyle : undefined}
1035 collapsable={false}
1036 importantForAccessibility={floatingSidebarOpen ? "no-hide-descendants" : "auto"}
1037 accessibilityElementsHidden={floatingSidebarOpen}
1039 <Animated.View
1040 collapsable={false}
1041 style={[
1042 contentTargetWidth !== null
1043 ? {
1044 flex: 1,
1045 width: contentTargetWidth,
1046 // The strip's column is wider than the pane; the pane sits at its start.
1047 alignSelf: contentAnchor.end && !stripSidebar ? "flex-end" : "flex-start",
1048 marginRight: contentAnchor.end && !stripSidebar ? contentEndGap : 0,
1050 : { flex: 1 },
1051 Platform.OS === "android" ? androidNavigatorLimit : undefined,
1052 ]}
1054 {/* Android holds the content still, so its floating controls keep its width. */}
1055 <WorkspaceContentWidthContext
1056 value={layout.usesSplitView && Platform.OS !== "android" ? renderedContentWidth : null}
1058 <WorkspaceSettledContentWidthContext
1059 value={Platform.OS === "android" && layout.usesSplitView ? contentTargetWidth : null}
1061 {/* Compact Settings keeps the bottom navigation under all of its pages. */}
1062 <SafeAreaInsetsContext
1063 value={
1064 floatingTabsEnabled &&
1065 (compactAndroidSettings || (layout.usesSplitView && workspacePage))
1066 ? {
1067 ...safeAreaInsets,
1068 bottom:
1069 safeAreaInsets.bottom +
1070 FLOATING_TABS.bottom +
1071 FLOATING_TABS.edge +
1072 floatingTabs.height,
1074 : compactAndroidSettings
1075 ? { ...safeAreaInsets, bottom: 0 }
1076 : safeAreaInsets
1079 <View className="flex-1">
1080 <PaneContext value="content">
1081 <SettingsWorkspaceLayout>{children}</SettingsWorkspaceLayout>
1082 </PaneContext>
1083 </View>
1084 </SafeAreaInsetsContext>
1085 {floatingTabsEnabled &&
1086 (compactAndroidSettings || (layout.usesSplitView && workspacePage)) ? (
1087 <FloatingWorkspaceTabs
1088 paneWidth={layout.usesSplitView ? (layout.listPaneWidth ?? undefined) : undefined}
1089 fillWidth={compactAndroidSettings}
1090 onNewThread={handleStartNewTask}
1091 />
1092 ) : compactAndroidSettings ? (
1093 <AndroidWorkspaceNavigation onNewThread={handleStartNewTask} />
1094 ) : null}
1095 </WorkspaceSettledContentWidthContext>
1096 </WorkspaceContentWidthContext>
1097 </Animated.View>
1098 </Animated.View>
1099 {sidebarFloats ? (
1100 <Animated.View
1101 className="absolute inset-0 bg-black"
1102 pointerEvents={floatingSidebarOpen ? "auto" : "none"}
1103 style={[{ zIndex: 1 }, scrimAnimatedStyle]}
1105 <Pressable
1106 accessibilityLabel="Hide sidebar"
1107 className="flex-1"
1108 onPress={() => setPrimarySidebarVisible(false)}
1109 />
1110 </Animated.View>
1111 ) : null}
1112 <PaneContext value="inspector">
1113 <WorkspaceInspectorPane
1114 renderedInspectorWidth={renderedInspectorWidth}
1115 active={workspaceInspector?.active ?? false}
1116 panes={panes}
1117 content={workspaceInspector?.content}
1118 setAuxiliaryPaneWidth={setFileInspectorPreferredWidth}
1119 onClose={() => setFileInspectorPreferredVisible(false)}
1120 onClosed={handleWorkspaceInspectorClosed}
1121 />
1122 </PaneContext>
1123 {inspectorSheet}
1124 {shouldRenderNavigationRail && navigationRailWidth > 0 ? (
1125 // Its trailing inset clips the old rail as soon as Android fits the workspace to a cover display.
1126 <View
1127 className="absolute inset-y-0 left-0 overflow-hidden"
1128 style={[
1129 railOverlay
1130 ? { right: 0 }
1131 : { right: viewportWidth - navigationRailWidth, maxWidth: navigationRailWidth },
1132 sidebarFloats ? { zIndex: 3, elevation: 8 } : null,
1133 ]}
1135 <AndroidWorkspaceNavigation
1136 onNewThread={handleStartNewTask}
1137 rail
1138 onSelect={revealPrimarySidebar}
1139 onOverlayChange={setRailOverlay}
1140 />
1141 </View>
1142 ) : null}
1143 </View>
1144 );
1145​
1146 return (
1147 <HomeListOptionsProvider
1148 projectGroupingMode={projectGroupingMode}
1149 savedFilters={props.savedThreadListFilters}
1151 <AdaptiveWorkspaceContext value={contextValue}>
1152 <WorkspacePaneStateContext value={paneState}>
1153 <WindowHingeContext value={windowHinge}>
1154 {usesPresentationHost ? (
1155 <WorkspaceColumnsRendererContext value={renderColumns}>
1156 {props.children}
1157 </WorkspaceColumnsRendererContext>
1158 ) : (
1159 renderColumns(props.children)
1160 )}
1161 </WindowHingeContext>
1162 </WorkspacePaneStateContext>
1163 </AdaptiveWorkspaceContext>
1164 </HomeListOptionsProvider>
1165 );