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