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