Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AdaptiveWorkspaceLayout.tsx

769 lines27.4 KB

1import type {
2 EnvironmentProject,
3 EnvironmentThreadShell,
4} from "@t3tools/client-runtime/state/shell";
5import { EnvironmentId, ThreadId, type SidebarProjectGroupingMode } from "@t3tools/contracts";
6import { useAtomValue } from "@effect/atom-react";
7import { useFocusEffect } from "@react-navigation/native";
8import {
9 CommonActions,
10 NavigationContext,
11 NavigationRouteContext,
12 StackActions,
13 useNavigation,
14} from "@react-navigation/native";
15import {
16 createContext,
17 use,
18 useCallback,
19 useEffect,
20 useMemo,
21 useRef,
22 useState,
23 type ReactNode,
24} from "react";
25import { Platform, useWindowDimensions, View } from "react-native";
26import Animated, {
27 runOnJS,
28 useAnimatedStyle,
29 useDerivedValue,
30 useSharedValue,
31 withTiming,
32} from "react-native-reanimated";
33import { AsyncResult } from "effect/reactivity";
34​
35import {
36 deriveFileInspectorPaneLayout,
37 deriveLayout,
38 deriveWorkspacePaneLayout,
39 type FileInspectorPaneLayout,
40 type Layout,
41 type WorkspaceAuxiliaryPaneRole,
42 type WorkspacePaneLayout,
43} from "../../lib/layout";
44import {
45 resolveThreadSelectionNavigationAction,
46 resolveThreadSelectionOverlayState,
47} from "../../lib/adaptive-navigation";
48import { scopedThreadKey } from "../../lib/scopedEntities";
49import type { ThreadListFilters } from "../../persistence/mobile-preferences";
50import { mobilePreferencesAtom } from "../../state/preferences";
51import {
52 DEFAULT_MOBILE_PROJECT_GROUPING_SETTINGS,
53 resolveMobileProjectGroupingSettings,
54} from "../../state/project-grouping";
55import {
56 parseActiveThreadPath,
57 useHardwareKeyboardCommand,
58} from "../keyboard/hardwareKeyboardCommands";
59import { AndroidHomeFabLayout } from "../home/AndroidHomeFab";
60import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
61import {
62 AndroidWorkspaceNavigation,
63 ANDROID_WORKSPACE_RAIL_WIDTH,
64} from "../workspace/AndroidWorkspaceNavigation";
65import { AndroidWorkspaceSidebar } from "../workspace/AndroidWorkspaceSidebar";
66import { useAndroidWorkspaceSelection } from "../workspace/useAndroidWorkspaceSelection";
67import { HomeListOptionsProvider } from "../home/home-list-options";
68import { ThreadNavigationSidebar } from "../threads/ThreadNavigationSidebar";
69import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderErrorBoundary";
70import { WORKSPACE_PANE_TIMING } from "./workspace-pane-animation";
71import { WorkspaceInspectorPane } from "./workspace-inspector-pane";
72import { WorkspaceContentWidthContext } from "./workspace-content-width";
73import {
74 NativeWorkspaceModeContext,
75 NativeWorkspaceInspectorContext,
76} from "../../native/v5-workspace-context";
77​
78import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
79​
80interface AdaptiveWorkspaceContextValue {
81 readonly layout: Layout;
82 readonly panes: WorkspacePaneLayout;
83 readonly fileInspector: FileInspectorPaneLayout;
84 readonly primarySidebarSearchQuery: string;
85 readonly selectThread: (thread: EnvironmentThreadShell) => void;
86 readonly activateAuxiliaryPaneRole: (role: WorkspaceAuxiliaryPaneRole) => () => void;
87 readonly registerWorkspaceInspector: (render: () => ReactNode) => () => void;
88 readonly setPrimarySidebarSearchQuery: (query: string) => void;
89 readonly showAuxiliaryPane: (role: WorkspaceAuxiliaryPaneRole) => void;
90 readonly toggleAuxiliaryPane: () => void;
91 readonly togglePrimarySidebar: () => void;
92 readonly setAuxiliaryPaneWidth: (width: number) => void;
94​
95const compactLayout = deriveLayout({ width: 0, height: 0 });
96const compactPanes = deriveWorkspacePaneLayout({
97 layout: compactLayout,
98 viewportWidth: 0,
99 primarySidebarPreferredVisible: true,
100 auxiliaryPanePreferredVisible: true,
101});
102const compactFileInspector = deriveFileInspectorPaneLayout({
103 layout: compactLayout,
104 viewportWidth: 0,
105});
106const AdaptiveWorkspaceContext = createContext<AdaptiveWorkspaceContextValue>({
107 layout: compactLayout,
108 panes: compactPanes,
109 fileInspector: compactFileInspector,
110 primarySidebarSearchQuery: "",
111 selectThread: () => undefined,
112 activateAuxiliaryPaneRole: () => () => undefined,
113 registerWorkspaceInspector: () => () => undefined,
114 setPrimarySidebarSearchQuery: () => undefined,
115 showAuxiliaryPane: () => undefined,
116 toggleAuxiliaryPane: () => undefined,
117 togglePrimarySidebar: () => undefined,
118 setAuxiliaryPaneWidth: () => undefined,
119});
120​
121export function useAdaptiveWorkspaceLayout(): AdaptiveWorkspaceContextValue {
122 return use(AdaptiveWorkspaceContext);
124​
125export function useAdaptiveWorkspacePaneRole(role: WorkspaceAuxiliaryPaneRole) {
126 const { activateAuxiliaryPaneRole } = useAdaptiveWorkspaceLayout();
127​
128 useFocusEffect(
129 useCallback(() => activateAuxiliaryPaneRole(role), [activateAuxiliaryPaneRole, role]),
130 );
132​
133/**
134 * The column renders BESIDE the navigator — outside any screen — so the
135 * registering screen's navigation and route contexts are captured here and
136 * re-provided around the portal content.
137 *
138 * Registration is FOCUS-scoped, driven by navigation events rather than the
139 * screen's own render cycle: react-native-screens freezes blurred screens, so a
140 * cleanup that depends on the blurred subtree re-rendering never runs and would
141 * leak the pane into the next route.
142 */
143export function useRegisterWorkspaceInspector(render: (() => ReactNode) | undefined) {
144 const { registerWorkspaceInspector } = useAdaptiveWorkspaceLayout();
145 const navigation = use(NavigationContext);
146 const route = use(NavigationRouteContext);
147​
148 const wrappedRender = useMemo(() => {
149 if (render === undefined) {
150 return undefined;
151 }
152 return () => (
153 <NavigationContext.Provider value={navigation}>
154 <NavigationRouteContext.Provider value={route}>{render()}</NavigationRouteContext.Provider>
155 </NavigationContext.Provider>
156 );
157 }, [navigation, render, route]);
158​
159 const wrappedRenderRef = useRef(wrappedRender);
160 wrappedRenderRef.current = wrappedRender;
161 const focusedRef = useRef(false);
162 const deactivateRef = useRef<(() => void) | null>(null);
163​
164 const syncRegistration = useCallback(() => {
165 if (!focusedRef.current || wrappedRenderRef.current === undefined) {
166 deactivateRef.current?.();
167 return;
168 }
169 deactivateRef.current = registerWorkspaceInspector(wrappedRenderRef.current);
170 }, [registerWorkspaceInspector]);
171​
172 useFocusEffect(
173 useCallback(() => {
174 focusedRef.current = true;
175 syncRegistration();
176 return () => {
177 focusedRef.current = false;
178 syncRegistration();
179 };
180 }, [syncRegistration]),
181 );
182​
183 useEffect(() => {
184 if (focusedRef.current) {
185 syncRegistration();
186 }
187 }, [syncRegistration, wrappedRender]);
188​
189 useEffect(
190 () => () => {
191 deactivateRef.current?.();
192 deactivateRef.current = null;
193 },
194 [],
195 );
197​
198export function AdaptiveWorkspaceLayout(props: {
199 readonly children: ReactNode;
200 readonly pathname: string;
201 readonly workspaceRouteKey: string | undefined;
202 readonly selectedPullRequestKey?: string | null;
203}) {
204 const preferencesResult = useAtomValue(mobilePreferencesAtom);
205 if (!AsyncResult.isSuccess(preferencesResult)) {
206 return AsyncResult.isFailure(preferencesResult) ? (
207 <AdaptiveWorkspaceLayoutContent
208 {...props}
209 projectGroupingMode={DEFAULT_MOBILE_PROJECT_GROUPING_SETTINGS.sidebarProjectGroupingMode}
210 />
211 ) : null;
212 }
213 const groupingSettings = resolveMobileProjectGroupingSettings(preferencesResult.value);
214 return (
215 <AdaptiveWorkspaceLayoutContent
216 {...props}
217 projectGroupingMode={groupingSettings.sidebarProjectGroupingMode}
218 savedThreadListFilters={preferencesResult.value.threadListFilters}
219 />
220 );
222​
223function AdaptiveWorkspaceLayoutContent(
224 props: {
225 readonly children: ReactNode;
226 readonly pathname: string;
227 readonly workspaceRouteKey: string | undefined;
228 readonly selectedPullRequestKey?: string | null;
229 } & {
230 readonly projectGroupingMode: SidebarProjectGroupingMode;
231 readonly savedThreadListFilters?: ThreadListFilters | undefined;
232 },
233) {
234 const projectGroupingMode = props.projectGroupingMode;
235 const nativeWorkspace = use(NativeWorkspaceModeContext);
236 const windowDimensions = useWindowDimensions();
237 const nativeMetrics = useNativeLayoutMetrics();
238 const { width: viewportWidth, height } = nativeMetrics ?? windowDimensions;
239 const { scale: androidControlScale } = useAndroidControlSizing();
240 const pathname = props.pathname;
241 const navigation = useNavigation();
242 const activeRoleOwner = useRef<symbol | null>(null);
243 const [primarySidebarPreferredVisible, setPrimarySidebarPreferredVisible] = useState(true);
244 const showPrimarySidebar = pathname === "/" || primarySidebarPreferredVisible;
245 const [supplementaryPanePreferredVisible, setSupplementaryPanePreferredVisible] = useState(true);
246 const [supplementaryPanePreferredWidth, setSupplementaryPanePreferredWidth] = useState<
247 number | null
248 >(null);
249 const [fileInspectorPreferredVisible, setFileInspectorPreferredVisible] = useState(true);
250 const [fileInspectorPreferredWidth, setFileInspectorPreferredWidth] = useState<number | null>(
251 null,
252 );
253 const [primarySidebarSearchQuery, setPrimarySidebarSearchQuery] = useState("");
254 const [focusedAuxiliaryPaneRole, setFocusedAuxiliaryPaneRole] =
255 useState<WorkspaceAuxiliaryPaneRole | null>(null);
256 const baseLayout = useMemo(
257 () => deriveLayout({ width: viewportWidth, height, nativeMetrics }),
258 [height, viewportWidth, nativeMetrics],
259 );
260 const layout = baseLayout;
261 const shouldRenderNavigationRail = Platform.OS === "android" && layout.usesSplitView;
262 const navigationRailWidth =
263 shouldRenderNavigationRail && showPrimarySidebar
264 ? ANDROID_WORKSPACE_RAIL_WIDTH * Math.max(1, androidControlScale)
265 : 0;
266 const width = viewportWidth - navigationRailWidth;
267 const shouldRenderPrimarySidebar = layout.usesSplitView;
268 const fileInspector = useMemo(
269 () =>
270 deriveFileInspectorPaneLayout({
271 layout,
272 viewportWidth: width,
273 preferredWidth: fileInspectorPreferredWidth ?? undefined,
274 reservedLeadingWidth:
275 shouldRenderPrimarySidebar && showPrimarySidebar
276 ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
277 : 0,
278 }),
279 [fileInspectorPreferredWidth, layout, showPrimarySidebar, shouldRenderPrimarySidebar, width],
280 );
281 const auxiliaryPaneRole: WorkspaceAuxiliaryPaneRole =
282 focusedAuxiliaryPaneRole ?? (/\/files(?:\/|$)/.test(pathname) ? "inspector" : "supplementary");
283 const auxiliaryPanePreferredVisible =
284 auxiliaryPaneRole === "inspector"
285 ? fileInspectorPreferredVisible
286 : supplementaryPanePreferredVisible;
287 const auxiliaryPanePreferredWidth =
288 auxiliaryPaneRole === "inspector"
289 ? fileInspectorPreferredWidth
290 : supplementaryPanePreferredWidth;
291 const panes = useMemo(
292 () =>
293 deriveWorkspacePaneLayout({
294 layout,
295 viewportWidth: width,
296 primarySidebarPreferredVisible: showPrimarySidebar,
297 auxiliaryPanePreferredVisible,
298 auxiliaryPaneRole,
299 auxiliaryPanePreferredWidth: auxiliaryPanePreferredWidth ?? undefined,
300 }),
301 [
302 auxiliaryPanePreferredVisible,
303 auxiliaryPaneRole,
304 auxiliaryPanePreferredWidth,
305 layout,
306 showPrimarySidebar,
307 width,
308 ],
309 );
310 const activeThread = parseActiveThreadPath(pathname);
311 const environmentId = activeThread?.environmentId ?? null;
312 const threadId = activeThread?.threadId ?? null;
313 const selectedThreadKey = useMemo(() => {
314 if (environmentId === null || threadId === null) {
315 return null;
316 }
317 try {
318 return scopedThreadKey(EnvironmentId.make(environmentId), ThreadId.make(threadId));
319 } catch {
320 return null;
321 }
322 }, [environmentId, threadId]);
323 const [workspaceInspector, setWorkspaceInspector] = useState<{
324 readonly render: () => ReactNode;
325 readonly active: boolean;
326 } | null>(null);
327 const workspaceInspectorOwner = useRef<symbol | null>(null);
328 const registerWorkspaceInspector = useCallback((render: () => ReactNode) => {
329 const owner = Symbol("workspace-inspector");
330 workspaceInspectorOwner.current = owner;
331 setWorkspaceInspector({ render, active: true });
332​
333 return () => {
334 // During a push/replace the outgoing screen deactivates AFTER the
335 // incoming screen registered — only the current owner may deactivate.
336 if (workspaceInspectorOwner.current !== owner) {
337 return;
338 }
339 setWorkspaceInspector((current) => (current === null ? null : { ...current, active: false }));
340 };
341 }, []);
342 const handleWorkspaceInspectorClosed = useCallback(() => {
343 setWorkspaceInspector((current) => (current !== null && !current.active ? null : current));
344 }, []);
345 const activateAuxiliaryPaneRole = useCallback((role: WorkspaceAuxiliaryPaneRole) => {
346 const owner = Symbol(role);
347 activeRoleOwner.current = owner;
348 setFocusedAuxiliaryPaneRole(role);
349​
350 return () => {
351 if (activeRoleOwner.current !== owner) {
352 return;
353 }
354 activeRoleOwner.current = null;
355 setFocusedAuxiliaryPaneRole(null);
356 };
357 }, []);
358 const togglePrimarySidebar = useCallback(() => {
359 if (pathname === "/") {
360 return;
361 }
362 if (!panes.primarySidebarVisible && panes.primarySidebarSuppressedByAuxiliary) {
363 setFileInspectorPreferredVisible(false);
364 setPrimarySidebarPreferredVisible(true);
365 return;
366 }
367 setPrimarySidebarPreferredVisible((current) => !current);
368 }, [panes.primarySidebarSuppressedByAuxiliary, panes.primarySidebarVisible, pathname]);
369 const revealPrimarySidebar = useCallback(() => {
370 if (panes.primarySidebarSuppressedByAuxiliary) {
371 setFileInspectorPreferredVisible(false);
372 }
373 setPrimarySidebarPreferredVisible(true);
374 }, [panes.primarySidebarSuppressedByAuxiliary]);
375 const handleToggleSidebarCommand = useCallback(() => {
376 togglePrimarySidebar();
377 return true;
378 }, [togglePrimarySidebar]);
379 const sidebarCommands = useMemo(
380 () => (pathname === "/" ? [] : (["toggleSidebar"] as const)),
381 [pathname],
382 );
383 useHardwareKeyboardCommand(sidebarCommands, handleToggleSidebarCommand);
384 const showAuxiliaryPane = useCallback((role: WorkspaceAuxiliaryPaneRole) => {
385 if (role === "inspector") {
386 setFocusedAuxiliaryPaneRole("inspector");
387 setFileInspectorPreferredVisible(true);
388 return;
389 }
390 setFocusedAuxiliaryPaneRole("supplementary");
391 setSupplementaryPanePreferredVisible(true);
392 }, []);
393 const handleOpenFilesCommand = useCallback(() => {
394 const activeThread = parseActiveThreadPath(pathname);
395 if (!layout.usesSplitView || !fileInspector.supported || activeThread === null) {
396 return false;
397 }
398 showAuxiliaryPane("inspector");
399 if (/\/files(?:\/|$)/.test(pathname)) {
400 return true;
401 }
402 navigation.navigate("ThreadFiles", activeThread);
403 return true;
404 }, [fileInspector.supported, layout.usesSplitView, pathname, navigation, showAuxiliaryPane]);
405 useHardwareKeyboardCommand("files", handleOpenFilesCommand);
406 const toggleAuxiliaryPane = useCallback(() => {
407 if (auxiliaryPaneRole === "inspector") {
408 setFileInspectorPreferredVisible((current) => !current);
409 return;
410 }
411 setSupplementaryPanePreferredVisible((current) => !current);
412 }, [auxiliaryPaneRole]);
413 const setAuxiliaryPaneWidth = useCallback(
414 (nextWidth: number) => {
415 if (auxiliaryPaneRole === "inspector") {
416 setFileInspectorPreferredWidth(nextWidth);
417 return;
418 }
419 setSupplementaryPanePreferredWidth(nextWidth);
420 },
421 [auxiliaryPaneRole],
422 );
423 const handleOpenSettings = useCallback(() => {
424 navigation.navigate("SettingsSheet", {
425 screen: "SettingsContent",
426 params: { screen: "Settings" },
427 });
428 }, [navigation]);
429​
430 const handleStartNewTask = useCallback(() => {
431 navigation.navigate("NewTaskSheet", { screen: "NewTask" });
432 }, [navigation]);
433​
434 // Minted here (root stack navigation) so the sidebar pane stays free of
435 // navigation hooks — on iOS it renders inside an independent nav tree.
436 const handleOpenEnvironmentSettings = useCallback(() => {
437 navigation.navigate("SettingsSheet", {
438 screen: "SettingsContent",
439 params: { screen: "SettingsEnvironments" },
440 });
441 }, [navigation]);
442​
443 const handleNewThreadOnBranch = useCallback(
444 (thread: EnvironmentThreadShell) => {
445 navigation.navigate("NewTaskSheet", {
446 screen: "NewTaskDraft",
447 params: {
448 environmentId: String(thread.environmentId),
449 projectId: String(thread.projectId),
450 branch: thread.branch,
451 worktreePath: thread.worktreePath,
452 },
453 });
454 },
455 [navigation],
456 );
457​
458 const handleNewThreadInProject = useCallback(
459 (project: EnvironmentProject) => {
460 navigation.navigate("NewTaskSheet", {
461 screen: "NewTaskDraft",
462 params: {
463 environmentId: String(project.environmentId),
464 projectId: String(project.id),
465 title: project.title,
466 },
467 });
468 },
469 [navigation],
470 );
471​
472 const inspectorColumnTargetWidth =
473 workspaceInspector !== null && workspaceInspector.active && panes.auxiliaryPaneVisible
474 ? (panes.auxiliaryPaneWidth ?? 0)
475 : 0;
476 const contentTargetWidth = layout.usesSplitView
477 ? Math.max(0, panes.contentPaneWidth - inspectorColumnTargetWidth)
478 : null;
479 const [contentSizing, setContentSizing] = useState({
480 viewportWidth,
481 target: contentTargetWidth,
482 sidebarVisible: panes.primarySidebarVisible,
483 width: contentTargetWidth,
484 revision: 0,
485 });
486 if (
487 Platform.OS === "android" &&
488 (contentSizing.viewportWidth !== viewportWidth ||
489 contentSizing.target !== contentTargetWidth ||
490 contentSizing.sidebarVisible !== panes.primarySidebarVisible)
491 ) {
492 const openingSidebar =
493 Platform.OS === "android" &&
494 contentSizing.viewportWidth === viewportWidth &&
495 !contentSizing.sidebarVisible &&
496 panes.primarySidebarVisible &&
497 contentSizing.width !== null &&
498 contentTargetWidth !== null;
499 setContentSizing({
500 viewportWidth,
501 target: contentTargetWidth,
502 sidebarVisible: panes.primarySidebarVisible,
503 width: openingSidebar
504 ? Math.max(contentSizing.width ?? 0, contentTargetWidth ?? 0)
505 : contentTargetWidth,
506 revision: contentSizing.revision + 1,
507 });
508 }
509 const settleContentWidth = useCallback((revision: number) => {
510 setContentSizing((current) =>
511 current.revision !== revision || current.width === current.target
512 ? current
513 : { ...current, width: current.target },
514 );
515 }, []);
516 const contentSettledWidth = Platform.OS === "android" ? contentSizing.width : contentTargetWidth;
517 const contentRevision = contentSizing.revision;
518​
519 const renderedSidebarWidth = useSharedValue(
520 panes.primarySidebarVisible ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0) : 0,
521 );
522 const renderedRailWidth = useSharedValue(navigationRailWidth);
523 useEffect(() => {
524 if (nativeWorkspace) return;
525 const targetWidth = panes.primarySidebarVisible
526 ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
527 : 0;
528 renderedSidebarWidth.value = withTiming(targetWidth, WORKSPACE_PANE_TIMING, (finished) => {
529 if (finished && Platform.OS === "android") runOnJS(settleContentWidth)(contentRevision);
530 });
531 renderedRailWidth.set(withTiming(navigationRailWidth, WORKSPACE_PANE_TIMING));
532 }, [
533 nativeWorkspace,
534 navigationRailWidth,
535 layout.listPaneWidth,
536 layout.listPaneGap,
537 panes.primarySidebarVisible,
538 renderedSidebarWidth,
539 renderedRailWidth,
540 settleContentWidth,
541 contentRevision,
542 ]);
543 const railAnimatedStyle = useAnimatedStyle(() => ({ width: renderedRailWidth.value }));
544 const sidebarAnimatedStyle = useAnimatedStyle(() => ({
545 // Fading a UIKit glass ancestor can leave remounted header effects missing.
546 opacity: Platform.OS === "ios" ? 1 : Math.min(1, renderedSidebarWidth.value / 80),
547 width: renderedSidebarWidth.value,
548 }));
549​
550 // The navigator (native header + markdown feed) lays out ONCE per pane toggle
551 // instead of re-measuring on every animation frame — the animating columns
552 // merely clip/reveal it over a matching background.
553 const renderedInspectorWidth = useSharedValue(inspectorColumnTargetWidth);
554 const renderedContentWidth = useDerivedValue(() =>
555 Math.max(
556 0,
557 viewportWidth -
558 renderedRailWidth.value -
559 renderedSidebarWidth.value -
560 renderedInspectorWidth.value,
561 ),
562 );
563​
564 const selectAndroidWorkspace = useAndroidWorkspaceSelection();
565 const handleSelectThread = useCallback(
566 (thread: EnvironmentThreadShell) => {
567 const params = {
568 environmentId: String(thread.environmentId),
569 threadId: String(thread.id),
570 };
571 if (Platform.OS === "android") {
572 setFileInspectorPreferredVisible(false);
573 selectAndroidWorkspace({ name: "Thread", params });
574 return;
575 }
576 const navigationAction = resolveThreadSelectionNavigationAction({
577 usesSplitView: layout.usesSplitView,
578 pathname,
579 });
580 const overlayState = resolveThreadSelectionOverlayState({
581 state: navigation.getState(),
582 workspaceRouteKey: props.workspaceRouteKey,
583 action: navigationAction,
584 params,
585 });
586 if (overlayState !== null) {
587 setFileInspectorPreferredVisible(false);
588 navigation.dispatch(CommonActions.reset(overlayState));
589 return;
590 }
591 if (navigationAction === "set-params") {
592 const nextThreadKey = scopedThreadKey(thread.environmentId, thread.id);
593 if (nextThreadKey === selectedThreadKey) {
594 return;
595 }
596 setFileInspectorPreferredVisible(false);
597 navigation.navigate("Thread", params);
598 return;
599 }
600 if (navigationAction === "replace") {
601 setFileInspectorPreferredVisible(false);
602 navigation.dispatch(StackActions.replace("Thread", params));
603 return;
604 }
605 navigation.navigate("Thread", params);
606 },
607 [
608 layout.usesSplitView,
609 pathname,
610 navigation,
611 selectedThreadKey,
612 props.workspaceRouteKey,
613 selectAndroidWorkspace,
614 ],
615 );
616​
617 const contextValue = useMemo(
618 () => ({
619 layout,
620 panes,
621 fileInspector,
622 primarySidebarSearchQuery,
623 selectThread: handleSelectThread,
624 activateAuxiliaryPaneRole,
625 registerWorkspaceInspector,
626 setPrimarySidebarSearchQuery,
627 showAuxiliaryPane,
628 toggleAuxiliaryPane,
629 togglePrimarySidebar,
630 setAuxiliaryPaneWidth,
631 }),
632 [
633 activateAuxiliaryPaneRole,
634 fileInspector,
635 handleSelectThread,
636 layout,
637 panes,
638 primarySidebarSearchQuery,
639 registerWorkspaceInspector,
640 showAuxiliaryPane,
641 setPrimarySidebarSearchQuery,
642 setAuxiliaryPaneWidth,
643 toggleAuxiliaryPane,
644 togglePrimarySidebar,
645 ],
646 );
647​
648 if (nativeWorkspace) {
649 return (
650 <HomeListOptionsProvider
651 projectGroupingMode={projectGroupingMode}
652 savedFilters={props.savedThreadListFilters}
653 >
654 <AdaptiveWorkspaceContext value={contextValue}>
655 <NativeWorkspaceInspectorContext
656 value={{ render: workspaceInspector?.render, visible: inspectorColumnTargetWidth > 0 }}
657 >
658 {props.children}
659 </NativeWorkspaceInspectorContext>
660 </AdaptiveWorkspaceContext>
661 </HomeListOptionsProvider>
662 );
663 }
664 return (
665 <HomeListOptionsProvider
666 projectGroupingMode={projectGroupingMode}
667 savedFilters={props.savedThreadListFilters}
668 >
669 <AdaptiveWorkspaceContext.Provider value={contextValue}>
670 <View
671 testID="adaptive-workspace-layout"
672 className={Platform.OS === "android" ? "flex-1 flex-row bg-header" : "flex-1 flex-row"}
673 >
674 {shouldRenderNavigationRail ? (
675 <Animated.View
676 className="self-stretch overflow-hidden"
677 accessibilityElementsHidden={navigationRailWidth === 0}
678 importantForAccessibility={navigationRailWidth > 0 ? "auto" : "no-hide-descendants"}
679 pointerEvents={navigationRailWidth > 0 ? "auto" : "none"}
680 style={railAnimatedStyle}
681 >
682 <AndroidWorkspaceNavigation rail onSelect={revealPrimarySidebar} />
683 </Animated.View>
684 ) : null}
685 {shouldRenderPrimarySidebar && layout.listPaneWidth !== null ? (
686 <Animated.View
687 className="self-stretch overflow-hidden"
688 accessibilityElementsHidden={!panes.primarySidebarVisible}
689 collapsable={false}
690 importantForAccessibility={
691 panes.primarySidebarVisible ? "auto" : "no-hide-descendants"
692 }
693 pointerEvents={panes.primarySidebarVisible ? "auto" : "none"}
694 style={sidebarAnimatedStyle}
695 >
696 <View className="flex-1" style={{ width: layout.listPaneWidth }}>
697 <RenderErrorBoundary
698 renderFallback={(fallback) => (
699 <RenderFailureView
700 {...fallback}
701 title="The sidebar couldn't be displayed"
702 exit={{ label: "Open settings", onPress: handleOpenSettings }}
703 />
704 )}
705 >
706 <AndroidWorkspaceSidebar
707 onRequestVisibility={revealPrimarySidebar}
708 selectedPullRequestKey={props.selectedPullRequestKey ?? null}
709 >
710 <AndroidHomeFabLayout sidebar onStartNewTask={handleStartNewTask}>
711 <ThreadNavigationSidebar
712 width={layout.listPaneWidth}
713 visible={panes.primarySidebarVisible}
714 onRequestVisibility={revealPrimarySidebar}
715 selectedThreadKey={selectedThreadKey}
716 onOpenSettings={handleOpenSettings}
717 onOpenEnvironmentSettings={handleOpenEnvironmentSettings}
718 onNewThreadInProject={handleNewThreadInProject}
719 onNewThreadOnBranch={handleNewThreadOnBranch}
720 onSelectThread={handleSelectThread}
721 onSearchQueryChange={setPrimarySidebarSearchQuery}
722 searchQuery={primarySidebarSearchQuery}
723 />
724 </AndroidHomeFabLayout>
725 </AndroidWorkspaceSidebar>
726 </RenderErrorBoundary>
727 </View>
728 </Animated.View>
729 ) : null}
730 <View
731 className={
732 Platform.OS === "android"
733 ? "flex-1 overflow-hidden bg-header"
734 : "flex-1 overflow-hidden bg-screen"
735 }
736 collapsable={false}
737 >
738 <View
739 collapsable={false}
740 style={
741 contentSettledWidth !== null
742 ? {
743 flex: 1,
744 width: contentSettledWidth,
745 }
746 : { flex: 1 }
747 }
748 >
749 <WorkspaceContentWidthContext
750 value={layout.usesSplitView ? renderedContentWidth : null}
751 >
752 {props.children}
753 </WorkspaceContentWidthContext>
754 </View>
755 </View>
756 <WorkspaceInspectorPane
757 pathname={props.pathname}
758 renderedInspectorWidth={renderedInspectorWidth}
759 active={workspaceInspector?.active ?? false}
760 panes={panes}
761 renderInspector={workspaceInspector?.render}
762 setAuxiliaryPaneWidth={setAuxiliaryPaneWidth}
763 onClosed={handleWorkspaceInspectorClosed}
764 />
765 </View>
766 </AdaptiveWorkspaceContext.Provider>
767 </HomeListOptionsProvider>
768 );