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

AdaptiveWorkspaceLayout.tsx

1,202 lines48.7 KB

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