Open History to see the last commit
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;
191}
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;
219}
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 );
244}
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 // A floating sidebar brings the rail with it.
366 const width = viewportWidth - (sidebarFloats ? 0 : 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 ? 0
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(() => ({ left: renderedRailWidth.value }));
798 const floatingSidebarOpen = sidebarFloats && panes.primarySidebarVisible;
799 // Its own value, so a sidebar that was beside a list doesn't dim the page as it leaves.
800 const scrimOpacity = useSharedValue(0);
801 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- animates the Reanimated scrim with the floating sidebar
802 useEffect(() => {
803 scrimOpacity.set(withTiming(floatingSidebarOpen ? 0.32 : 0, WORKSPACE_PANE_TIMING));
804 }, [floatingSidebarOpen, scrimOpacity]);
805 const scrimAnimatedStyle = useAnimatedStyle(() => ({ opacity: scrimOpacity.value }));
806 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Back closes a floating sidebar before it leaves the page
807 useEffect(() => {
808 if (!floatingSidebarOpen || nativeWorkspace) return;
809 const subscription = BackHandler.addEventListener("hardwareBackPress", () => {
810 // A sheet or modal over the workspace takes Back first.
811 const state = rootStackState(navigation);
812 if (state && workspaceRoutesOf(state.routes.slice(0, state.index + 1)).overlays.length > 0) {
813 return false;
814 }
815 setPrimarySidebarVisible(false);
816 return true;
817 });
818 return () => subscription.remove();
819 }, [floatingSidebarOpen, nativeWorkspace, navigation, setPrimarySidebarVisible]);
820 // Showing or hiding the sidebar clips a fixed-width list. A hinge resize instead tracks the
821 // animated edge, so the header actions slide with it rather than jumping or being covered.
822 const listPaneGap = layout.listPaneGap ?? 0;
823 const listPaneAnimatedStyle = useAnimatedStyle(() => ({
824 width: Math.min(
825 listPaneCeiling,
826 Math.max(
827 listPaneFloor,
828 (stripSidebar ? sidebarSlotWidth : renderedSidebarWidth.value) - listPaneGap,
829 ),
830 ),
831 }));
832 // How far the strip has slid: 0 with the sidebar shown, minus its width with it gone.
833 const stripOffset = useDerivedValue(() =>
834 stripSidebar ? renderedSidebarWidth.value - sidebarSlotWidth : 0,
835 );
836 const sidebarAnimatedStyle = useAnimatedStyle(() => ({
837 // Fading a UIKit glass ancestor can leave remounted header effects missing.
838 opacity:
839 stripSidebar || Platform.OS === "ios" || floatingTabsEnabled
840 ? 1
841 : Math.min(1, renderedSidebarWidth.value / 80),
842 width: stripSidebar ? sidebarSlotWidth : renderedSidebarWidth.value,
843 flexShrink: stripSidebar ? 0 : 1,
844 transform: [{ translateX: stripOffset.value }],
845 }));
846
847 // Clip the navigator at its settled width so native headers and markdown reflow only once per pane toggle.
848 const renderedInspectorWidth = useSharedValue(inspectorColumnTargetWidth);
849 const renderedContentWidth = useDerivedValue(() =>
850 Math.max(
851 0,
852 viewportWidth -
853 (sidebarFloats ? 0 : renderedRailWidth.value) -
854 (workspacePage || sidebarFloats ? 0 : renderedSidebarWidth.value) -
855 renderedInspectorWidth.value,
856 ),
857 );
858 // Android can resize the native row before React removes its split panes on a fold.
859 const androidSplit = Platform.OS === "android" && layout.usesSplitView;
860 // In the strip the column itself slides with the sidebar: Android only delivers touches inside a
861 // parent's bounds, so content may not slide out of its column. Every branch sets every key:
862 // Reanimated keeps a key a branch drops, so a fold mid-slide would leave the column shifted.
863 const androidContentSlotStyle = useAnimatedStyle(() =>
864 !androidSplit
865 ? { width: "100%" as const, marginRight: 0, transform: [{ translateX: 0 }] }
866 : stripSidebar
867 ? {
868 // Wide enough for the pane at either width; the margin gives the sidebar's share
869 // back to the row, so a column after it stays put while the strip slides.
870 width: Math.max(
871 0,
872 viewportWidth - renderedRailWidth.value - renderedInspectorWidth.value,
873 ),
874 marginRight: -sidebarSlotWidth,
875 transform: [{ translateX: stripOffset.value }],
876 }
877 : { width: renderedContentWidth.value, marginRight: 0, transform: [{ translateX: 0 }] },
878 );
879 // While the sidebar animates, clip the settled navigator instead of reflowing its text every frame.
880 // In the strip it lifts entirely: the content outgrows its column, and a cap that follows
881 // React's width would clip the wider layout for the frame it lands.
882 const androidNavigatorLimit = useAnimatedStyle(() => ({
883 maxWidth: stripSidebar
884 ? viewportWidth
885 : androidSplit &&
886 contentTargetWidth !== null &&
887 renderedContentWidth.value < contentTargetWidth
888 ? contentTargetWidth
889 : ("100%" as const),
890 }));
891
892 // Rotating flips the overlay; until the new size reaches JS, predict the reset above.
893 const sidebarOverRotates =
894 nativeWorkspace && nativeMetrics?.hasHinge === true && layout.usesSplitView;
895 // The current orientation's panes already account for an inspector that needs the sidebar's room.
896 const sidebarInLandscape =
897 baseLayout.variant === "medium"
898 ? primarySidebarPinned || primarySidebarPreferredVisible
899 : panes.primarySidebarVisible;
900 const sidebarInPortrait =
901 primarySidebarPinned ||
902 (baseLayout.variant === "medium" ? overlaySidebar.visible : isWorkspaceListPath(pathname));
903 const sidebarByOrientation = useMemo(
904 () =>
905 sidebarOverRotates ? { landscape: sidebarInLandscape, portrait: sidebarInPortrait } : null,
906 [sidebarInLandscape, sidebarInPortrait, sidebarOverRotates],
907 );
908
909 const actions = useStableActions({
910 startNewTask: handleStartNewTask,
911 selectDetail: handleSelectDetail,
912 registerWorkspaceInspector,
913 setPrimarySidebarSearchQuery,
914 showInspector,
915 toggleAuxiliaryPane,
916 togglePrimarySidebar,
917 revealPrimarySidebar,
918 setPrimarySidebarVisible,
919 openWorkspaceTab,
920 setAuxiliaryPaneWidth: setFileInspectorPreferredWidth,
921 setNativeInspectorWidth: (width: number) =>
922 setNativeInspectorWidthFraction(inspectorWidthFor(width / viewportWidth) / viewportWidth),
923 });
924 const contextValue = useMemo(
925 () => ({ ...actions, layout, nativeInspectorWidth, workspacePageWidth }),
926 [actions, layout, nativeInspectorWidth, workspacePageWidth],
927 );
928 const sidebarToggleable = layout.usesSplitView && !primarySidebarPinned && !workspacePage;
929 const paneState = useMemo(
930 () => ({
931 panes,
932 fileInspector,
933 primarySidebarSearchQuery,
934 sidebarToggleable,
935 sidebarByOrientation,
936 }),
937 [panes, fileInspector, primarySidebarSearchQuery, sidebarToggleable, sidebarByOrientation],
938 );
939
940 const inspectorSheet = (
941 <WorkspaceInspectorSheet
942 open={inspectorSheetOpen}
943 onClose={dismissInspectorSheet}
944 content={workspaceInspector?.content}
945 />
946 );
947 if (nativeWorkspace) {
948 return (
949 <HomeListOptionsProvider
950 projectGroupingMode={projectGroupingMode}
951 savedFilters={props.savedThreadListFilters}
952 >
953 <AdaptiveWorkspaceContext value={contextValue}>
954 <WorkspacePaneStateContext value={paneState}>
955 <NativeWorkspaceInspectorContext
956 value={{
957 // Without a column the sheet shows it; the hidden native column must not mount it too.
958 content: fileInspector.supported ? workspaceInspector?.content : undefined,
959 visible: inspectorColumnTargetWidth > 0,
960 }}
961 >
962 {props.children}
963 {inspectorSheet}
964 </NativeWorkspaceInspectorContext>
965 </WorkspacePaneStateContext>
966 </AdaptiveWorkspaceContext>
967 </HomeListOptionsProvider>
968 );
969 }
970 const renderColumns = (children: ReactNode, sidebar?: ReactNode) => (
971 <View
972 testID="adaptive-workspace-layout"
973 className={Platform.OS === "android" ? "flex-1 flex-row bg-header" : "flex-1 flex-row"}
974 >
975 <AndroidHingeObserver onChange={handleHingeChange} />
976 {shouldRenderNavigationRail ? (
977 <Animated.View
978 className={sidebarFloats ? "absolute inset-y-0 left-0" : "shrink self-stretch"}
979 style={railAnimatedStyle}
980 />
981 ) : null}
982 {shouldRenderPrimarySidebar && layout.listPaneWidth !== null ? (
983 <Animated.View
984 className="self-stretch overflow-hidden android:shrink"
985 accessibilityElementsHidden={workspacePage || !panes.primarySidebarVisible}
986 collapsable={false}
987 importantForAccessibility={
988 !workspacePage && panes.primarySidebarVisible ? "auto" : "no-hide-descendants"
989 }
990 pointerEvents={!workspacePage && panes.primarySidebarVisible ? "auto" : "none"}
991 // Under a workspace page the sidebar leaves the row but keeps its size, so its
992 // lists never lay out at zero size and are ready, unchanged, on the way back. The
993 // content pane, laid out after it, covers it, in the same mount as the page.
994 style={[
995 workspacePage ? { position: "absolute", top: 0, bottom: 0, left: 0 } : null,
996 sidebarFloats
997 ? [
998 { position: "absolute", top: 0, bottom: 0, zIndex: 2, elevation: 8 },
999 floatingSidebarAnimatedStyle,
1000 ]
1001 : null,
1002 sidebarAnimatedStyle,
1003 ]}
1004 >
1005 <Animated.View className="flex-1" style={listPaneAnimatedStyle}>
1006 <PaneContext value="sidebar">
1007 <RenderErrorBoundary
1008 renderFallback={(fallback) => (
1009 <RenderFailureView
1010 {...fallback}
1011 title="The sidebar couldn't be displayed"
1012 exit={{ label: "Open settings", onPress: handleOpenSettings }}
1013 />
1014 )}
1015 >
1016 {/* Without a sidebar route (iPadOS before 26) the columns draw the thread list. */}
1017 {sidebar ?? <WorkspaceThreadSidebar />}
1018 </RenderErrorBoundary>
1019 </PaneContext>
1020 {/* Keep the pill under the content throughout the sidebar's clipping animation. */}
1021 {floatingTabsEnabled && !workspacePage ? (
1022 <FloatingWorkspaceTabs
1023 paneWidth={layout.listPaneWidth}
1024 onNewThread={handleStartNewTask}
1025 onSelect={revealPrimarySidebar}
1026 />
1027 ) : null}
1028 </Animated.View>
1029 </Animated.View>
1030 ) : null}
1031 <Animated.View
1032 className={
1033 Platform.OS === "android"
1034 ? "max-w-full shrink-0 overflow-hidden bg-header"
1035 : "flex-1 overflow-hidden bg-screen"
1036 }
1037 style={Platform.OS === "android" ? androidContentSlotStyle : undefined}
1038 collapsable={false}
1039 importantForAccessibility={floatingSidebarOpen ? "no-hide-descendants" : "auto"}
1040 accessibilityElementsHidden={floatingSidebarOpen}
1041 >
1042 <Animated.View
1043 collapsable={false}
1044 style={[
1045 contentTargetWidth !== null
1046 ? {
1047 flex: 1,
1048 width: contentTargetWidth,
1049 // The strip's column is wider than the pane; the pane sits at its start.
1050 alignSelf: contentAnchor.end && !stripSidebar ? "flex-end" : "flex-start",
1051 marginRight: contentAnchor.end && !stripSidebar ? contentEndGap : 0,
1052 }
1053 : { flex: 1 },
1054 Platform.OS === "android" ? androidNavigatorLimit : undefined,
1055 ]}
1056 >
1057 {/* Android holds the content still, so its floating controls keep its width. */}
1058 <WorkspaceContentWidthContext
1059 value={layout.usesSplitView && Platform.OS !== "android" ? renderedContentWidth : null}
1060 >
1061 <WorkspaceSettledContentWidthContext
1062 value={Platform.OS === "android" && layout.usesSplitView ? contentTargetWidth : null}
1063 >
1064 {/* Compact Settings keeps the bottom navigation under all of its pages. */}
1065 <SafeAreaInsetsContext
1066 value={
1067 floatingTabsEnabled &&
1068 (compactAndroidSettings || (layout.usesSplitView && workspacePage))
1069 ? {
1070 ...safeAreaInsets,
1071 bottom:
1072 safeAreaInsets.bottom +
1073 FLOATING_TABS.bottom +
1074 FLOATING_TABS.edge +
1075 floatingTabs.height,
1076 }
1077 : compactAndroidSettings
1078 ? { ...safeAreaInsets, bottom: 0 }
1079 : safeAreaInsets
1080 }
1081 >
1082 <View className="flex-1">
1083 <PaneContext value="content">
1084 <SettingsWorkspaceLayout>{children}</SettingsWorkspaceLayout>
1085 </PaneContext>
1086 </View>
1087 </SafeAreaInsetsContext>
1088 {floatingTabsEnabled &&
1089 (compactAndroidSettings || (layout.usesSplitView && workspacePage)) ? (
1090 <FloatingWorkspaceTabs
1091 paneWidth={layout.usesSplitView ? (layout.listPaneWidth ?? undefined) : undefined}
1092 fillWidth={compactAndroidSettings}
1093 onNewThread={handleStartNewTask}
1094 />
1095 ) : compactAndroidSettings ? (
1096 <AndroidWorkspaceNavigation onNewThread={handleStartNewTask} />
1097 ) : null}
1098 </WorkspaceSettledContentWidthContext>
1099 </WorkspaceContentWidthContext>
1100 </Animated.View>
1101 </Animated.View>
1102 {sidebarFloats ? (
1103 <Animated.View
1104 className="absolute inset-0 bg-black"
1105 pointerEvents={floatingSidebarOpen ? "auto" : "none"}
1106 style={[{ zIndex: 1 }, scrimAnimatedStyle]}
1107 >
1108 <Pressable
1109 accessibilityLabel="Hide sidebar"
1110 className="flex-1"
1111 onPress={() => setPrimarySidebarVisible(false)}
1112 />
1113 </Animated.View>
1114 ) : null}
1115 <PaneContext value="inspector">
1116 <WorkspaceInspectorPane
1117 renderedInspectorWidth={renderedInspectorWidth}
1118 active={workspaceInspector?.active ?? false}
1119 panes={panes}
1120 content={workspaceInspector?.content}
1121 setAuxiliaryPaneWidth={setFileInspectorPreferredWidth}
1122 onClose={() => setFileInspectorPreferredVisible(false)}
1123 onClosed={handleWorkspaceInspectorClosed}
1124 />
1125 </PaneContext>
1126 {inspectorSheet}
1127 {shouldRenderNavigationRail && navigationRailWidth > 0 ? (
1128 // Its trailing inset clips the old rail as soon as Android fits the workspace to a cover display.
1129 <View
1130 className="absolute inset-y-0 left-0 overflow-hidden"
1131 style={[
1132 railOverlay
1133 ? { right: 0 }
1134 : { right: viewportWidth - navigationRailWidth, maxWidth: navigationRailWidth },
1135 sidebarFloats ? { zIndex: 3, elevation: 8 } : null,
1136 ]}
1137 >
1138 <AndroidWorkspaceNavigation
1139 onNewThread={handleStartNewTask}
1140 rail
1141 onSelect={revealPrimarySidebar}
1142 onOverlayChange={setRailOverlay}
1143 />
1144 </View>
1145 ) : null}
1146 </View>
1147 );
1148
1149 return (
1150 <HomeListOptionsProvider
1151 projectGroupingMode={projectGroupingMode}
1152 savedFilters={props.savedThreadListFilters}
1153 >
1154 <AdaptiveWorkspaceContext value={contextValue}>
1155 <WorkspacePaneStateContext value={paneState}>
1156 <WindowHingeContext value={windowHinge}>
1157 {usesPresentationHost ? (
1158 <WorkspaceColumnsRendererContext value={renderColumns}>
1159 {props.children}
1160 </WorkspaceColumnsRendererContext>
1161 ) : (
1162 renderColumns(props.children)
1163 )}
1164 </WindowHingeContext>
1165 </WorkspacePaneStateContext>
1166 </AdaptiveWorkspaceContext>
1167 </HomeListOptionsProvider>
1168 );
1169}