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