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