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