Open History to see the last commit
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 useEffect,
19 useEffectEvent,
20 useRef,
21 useState,
22 type ReactNode,
23} from "react";
24import { Platform, useWindowDimensions, View } from "react-native";
25import Animated, {
26 runOnJS,
27 useAnimatedStyle,
28 useDerivedValue,
29 useSharedValue,
30 withTiming,
31} from "react-native-reanimated";
32import { AsyncResult } from "effect/reactivity";
33
34import {
35 deriveFileInspectorPaneLayout,
36 alignListPaneToHinge,
37 deriveLayout,
38 type VerticalHinge,
39 deriveWorkspacePaneLayout,
40 isPrimarySidebarPinned,
41 type FileInspectorPaneLayout,
42 type Layout,
43 type WorkspaceAuxiliaryPaneRole,
44 type WorkspacePaneLayout,
45} from "../../lib/layout";
46import {
47 resolveThreadSelectionNavigationAction,
48 resolveThreadSelectionOverlayState,
49} from "../../lib/adaptive-navigation";
50import { scopedThreadKey } from "../../lib/scopedEntities";
51import type { ThreadListFilters } from "../../persistence/mobile-preferences";
52import { mobilePreferencesAtom } from "../../state/preferences";
53import {
54 DEFAULT_MOBILE_PROJECT_GROUPING_SETTINGS,
55 resolveMobileProjectGroupingSettings,
56} from "../../state/project-grouping";
57import {
58 parseActiveThreadPath,
59 useHardwareKeyboardCommand,
60} from "../keyboard/hardwareKeyboardCommands";
61import { AndroidHomeFabLayout } from "../home/AndroidHomeFab";
62import { AndroidWorkspaceSidebar } from "../workspace/AndroidWorkspaceSidebar";
63import { useAndroidWorkspaceSelection } from "../workspace/useAndroidWorkspaceSelection";
64import { HomeListOptionsProvider } from "../home/home-list-options";
65import { ThreadNavigationSidebar } from "../threads/ThreadNavigationSidebar";
66import { useOpenThreadPullRequests } from "../threads/use-open-thread-pull-requests";
67import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderErrorBoundary";
68import { WORKSPACE_PANE_TIMING } from "./workspace-pane-animation";
69import { WorkspaceInspectorPane } from "./workspace-inspector-pane";
70import { WorkspaceContentWidthContext } from "./workspace-content-width";
71import {
72 NativeWorkspaceModeContext,
73 NativeWorkspaceInspectorContext,
74} from "../../native/v5-workspace-context";
75
76import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
77import { AndroidHingeObserver } from "../../native/AndroidHingeObserver";
78import { WindowHingeContext } from "../../native/window-hinge-context";
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;
93}
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);
123}
124
125export function useAdaptiveWorkspacePaneRole(role: WorkspaceAuxiliaryPaneRole) {
126 const { activateAuxiliaryPaneRole } = useAdaptiveWorkspaceLayout();
127
128 useFocusEffect(() => activateAuxiliaryPaneRole(role));
129}
130
131/**
132 * The column renders BESIDE the navigator — outside any screen — so the
133 * registering screen's navigation and route contexts are captured here and
134 * re-provided around the portal content.
135 *
136 * Registration is FOCUS-scoped, driven by navigation events rather than the
137 * screen's own render cycle: react-native-screens freezes blurred screens, so a
138 * cleanup that depends on the blurred subtree re-rendering never runs and would
139 * leak the pane into the next route.
140 */
141export function useRegisterWorkspaceInspector(render: (() => ReactNode) | undefined) {
142 const { registerWorkspaceInspector } = useAdaptiveWorkspaceLayout();
143 const navigation = use(NavigationContext);
144 const route = use(NavigationRouteContext);
145
146 const wrappedRender = (() => {
147 if (render === undefined) {
148 return undefined;
149 }
150 return () => (
151 <NavigationContext.Provider value={navigation}>
152 <NavigationRouteContext.Provider value={route}>{render()}</NavigationRouteContext.Provider>
153 </NavigationContext.Provider>
154 );
155 })();
156
157 const focusedRef = useRef(false);
158 const deactivateRef = useRef<(() => void) | null>(null);
159
160 // An effect event reads this render's pane without making the focus
161 // subscription re-run (and deactivate) every time the pane closure changes.
162 const syncRegistration = useEffectEvent(() => {
163 if (!focusedRef.current || wrappedRender === undefined) {
164 deactivateRef.current?.();
165 return;
166 }
167 deactivateRef.current = registerWorkspaceInspector(wrappedRender);
168 });
169
170 useFocusEffect(() => {
171 focusedRef.current = true;
172 syncRegistration();
173 return () => {
174 focusedRef.current = false;
175 syncRegistration();
176 };
177 });
178
179 useEffect(() => {
180 if (focusedRef.current) {
181 syncRegistration();
182 }
183 }, [wrappedRender]);
184
185 useEffect(
186 () => () => {
187 deactivateRef.current?.();
188 deactivateRef.current = null;
189 },
190 [],
191 );
192}
193
194export function AdaptiveWorkspaceLayout(props: {
195 readonly children: ReactNode;
196 readonly pathname: string;
197 readonly workspaceRouteKey: string | undefined;
198 readonly selectedPullRequestKey?: string | null;
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 selectedPullRequestKey?: string | null;
225 } & {
226 readonly projectGroupingMode: SidebarProjectGroupingMode;
227 readonly savedThreadListFilters?: ThreadListFilters | undefined;
228 },
229) {
230 const projectGroupingMode = props.projectGroupingMode;
231 const nativeWorkspace = use(NativeWorkspaceModeContext);
232 const windowDimensions = useWindowDimensions();
233 const nativeMetrics = useNativeLayoutMetrics();
234 const { width: viewportWidth, height } = nativeMetrics ?? windowDimensions;
235 const pathname = props.pathname;
236 const navigation = useNavigation();
237 const activeRoleOwner = useRef<symbol | null>(null);
238 const [primarySidebarPreferredVisible, setPrimarySidebarPreferredVisible] = useState(true);
239 const [supplementaryPanePreferredVisible, setSupplementaryPanePreferredVisible] = useState(true);
240 const [supplementaryPanePreferredWidth, setSupplementaryPanePreferredWidth] = useState<
241 number | null
242 >(null);
243 const [fileInspectorPreferredVisible, setFileInspectorPreferredVisible] = useState(true);
244 const [fileInspectorPreferredWidth, setFileInspectorPreferredWidth] = useState<number | null>(
245 null,
246 );
247 const [primarySidebarSearchQuery, setPrimarySidebarSearchQuery] = useState("");
248 const [focusedAuxiliaryPaneRole, setFocusedAuxiliaryPaneRole] =
249 useState<WorkspaceAuxiliaryPaneRole | null>(null);
250 const baseLayout = deriveLayout({ width: viewportWidth, height, nativeMetrics });
251 const primarySidebarPinned = isPrimarySidebarPinned({
252 pathname,
253 nativeWorkspace,
254 usesSplitView: baseLayout.usesSplitView,
255 });
256 const showPrimarySidebar = primarySidebarPinned || primarySidebarPreferredVisible;
257 const [hinge, setHinge] = useState<VerticalHinge | null>(null);
258 const [windowHinge, setWindowHinge] = useState<VerticalHinge | null>(null);
259 const handleHingeChange = (next: VerticalHinge | null, nextWindow: VerticalHinge | null) => {
260 setHinge(next);
261 setWindowHinge(nextWindow);
262 };
263 const layout = alignListPaneToHinge({ layout: baseLayout, hinge, viewportWidth });
264 const shouldRenderPrimarySidebar = layout.usesSplitView;
265 const fileInspector = deriveFileInspectorPaneLayout({
266 layout,
267 viewportWidth,
268 preferredWidth: fileInspectorPreferredWidth ?? undefined,
269 reservedLeadingWidth:
270 shouldRenderPrimarySidebar && showPrimarySidebar
271 ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
272 : 0,
273 });
274 const auxiliaryPaneRole: WorkspaceAuxiliaryPaneRole =
275 focusedAuxiliaryPaneRole ?? (/\/files(?:\/|$)/.test(pathname) ? "inspector" : "supplementary");
276 const auxiliaryPanePreferredVisible =
277 auxiliaryPaneRole === "inspector"
278 ? fileInspectorPreferredVisible
279 : supplementaryPanePreferredVisible;
280 const auxiliaryPanePreferredWidth =
281 auxiliaryPaneRole === "inspector"
282 ? fileInspectorPreferredWidth
283 : supplementaryPanePreferredWidth;
284 const panes = deriveWorkspacePaneLayout({
285 layout,
286 viewportWidth,
287 primarySidebarPreferredVisible: showPrimarySidebar,
288 auxiliaryPanePreferredVisible,
289 auxiliaryPaneRole,
290 auxiliaryPanePreferredWidth: auxiliaryPanePreferredWidth ?? undefined,
291 });
292 const activeThread = parseActiveThreadPath(pathname);
293 const environmentId = activeThread?.environmentId ?? null;
294 const threadId = activeThread?.threadId ?? null;
295 const selectedThreadKey = (() => {
296 if (environmentId === null || threadId === null) {
297 return null;
298 }
299 try {
300 return scopedThreadKey(EnvironmentId.make(environmentId), ThreadId.make(threadId));
301 } catch {
302 return null;
303 }
304 })();
305 const [workspaceInspector, setWorkspaceInspector] = useState<{
306 readonly render: () => ReactNode;
307 readonly active: boolean;
308 } | null>(null);
309 const workspaceInspectorOwner = useRef<symbol | null>(null);
310 const registerWorkspaceInspector = (render: () => ReactNode) => {
311 const owner = Symbol("workspace-inspector");
312 workspaceInspectorOwner.current = owner;
313 setWorkspaceInspector({ render, active: true });
314
315 return () => {
316 // During a push/replace the outgoing screen deactivates AFTER the
317 // incoming screen registered — only the current owner may deactivate.
318 if (workspaceInspectorOwner.current !== owner) {
319 return;
320 }
321 setWorkspaceInspector((current) => (current === null ? null : { ...current, active: false }));
322 };
323 };
324 const handleWorkspaceInspectorClosed = () => {
325 setWorkspaceInspector((current) => (current !== null && !current.active ? null : current));
326 };
327 const activateAuxiliaryPaneRole = (role: WorkspaceAuxiliaryPaneRole) => {
328 const owner = Symbol(role);
329 activeRoleOwner.current = owner;
330 setFocusedAuxiliaryPaneRole(role);
331
332 return () => {
333 if (activeRoleOwner.current !== owner) {
334 return;
335 }
336 activeRoleOwner.current = null;
337 setFocusedAuxiliaryPaneRole(null);
338 };
339 };
340 const togglePrimarySidebar = () => {
341 if (primarySidebarPinned) {
342 return;
343 }
344 if (!panes.primarySidebarVisible && panes.primarySidebarSuppressedByAuxiliary) {
345 setFileInspectorPreferredVisible(false);
346 setPrimarySidebarPreferredVisible(true);
347 return;
348 }
349 setPrimarySidebarPreferredVisible((current) => !current);
350 };
351 const revealPrimarySidebar = () => {
352 if (panes.primarySidebarSuppressedByAuxiliary) {
353 setFileInspectorPreferredVisible(false);
354 }
355 setPrimarySidebarPreferredVisible(true);
356 };
357 const handleToggleSidebarCommand = () => {
358 togglePrimarySidebar();
359 return true;
360 };
361 const sidebarCommands = primarySidebarPinned ? [] : (["toggleSidebar"] as const);
362 useHardwareKeyboardCommand(sidebarCommands, handleToggleSidebarCommand);
363 const showAuxiliaryPane = (role: WorkspaceAuxiliaryPaneRole) => {
364 if (role === "inspector") {
365 setFocusedAuxiliaryPaneRole("inspector");
366 setFileInspectorPreferredVisible(true);
367 return;
368 }
369 setFocusedAuxiliaryPaneRole("supplementary");
370 setSupplementaryPanePreferredVisible(true);
371 };
372 const handleOpenFilesCommand = () => {
373 const activeThread = parseActiveThreadPath(pathname);
374 if (!layout.usesSplitView || !fileInspector.supported || activeThread === null) {
375 return false;
376 }
377 showAuxiliaryPane("inspector");
378 if (/\/files(?:\/|$)/.test(pathname)) {
379 return true;
380 }
381 navigation.navigate("ThreadFiles", activeThread);
382 return true;
383 };
384 useHardwareKeyboardCommand("files", handleOpenFilesCommand);
385 const toggleAuxiliaryPane = () => {
386 if (auxiliaryPaneRole === "inspector") {
387 setFileInspectorPreferredVisible((current) => !current);
388 return;
389 }
390 setSupplementaryPanePreferredVisible((current) => !current);
391 };
392 const setAuxiliaryPaneWidth = (nextWidth: number) => {
393 if (auxiliaryPaneRole === "inspector") {
394 setFileInspectorPreferredWidth(nextWidth);
395 return;
396 }
397 setSupplementaryPanePreferredWidth(nextWidth);
398 };
399 const handleOpenSettings = () => {
400 navigation.navigate("SettingsSheet", {
401 screen: "SettingsContent",
402 params: { screen: "Settings" },
403 });
404 };
405
406 const handleStartNewTask = () => {
407 navigation.navigate("NewTaskSheet", { screen: "NewTask" });
408 };
409
410 // Minted here (root stack navigation) so the sidebar pane stays free of
411 // navigation hooks — on iOS it renders inside an independent nav tree.
412 const handleOpenEnvironmentSettings = () => {
413 navigation.navigate("SettingsSheet", {
414 screen: "SettingsContent",
415 params: { screen: "SettingsEnvironments" },
416 });
417 };
418
419 const handleOpenThreadPullRequests = useOpenThreadPullRequests();
420
421 const handleNewThreadOnBranch = (thread: EnvironmentThreadShell) => {
422 navigation.navigate("NewTaskSheet", {
423 screen: "NewTaskDraft",
424 params: {
425 environmentId: String(thread.environmentId),
426 projectId: String(thread.projectId),
427 branch: thread.branch,
428 worktreePath: thread.worktreePath,
429 },
430 });
431 };
432
433 const handleNewThreadInProject = (project: EnvironmentProject) => {
434 navigation.navigate("NewTaskSheet", {
435 screen: "NewTaskDraft",
436 params: {
437 environmentId: String(project.environmentId),
438 projectId: String(project.id),
439 title: project.title,
440 },
441 });
442 };
443
444 const inspectorColumnTargetWidth =
445 workspaceInspector !== null && workspaceInspector.active && panes.auxiliaryPaneVisible
446 ? (panes.auxiliaryPaneWidth ?? 0)
447 : 0;
448 const contentTargetWidth = layout.usesSplitView
449 ? Math.max(0, panes.contentPaneWidth - inspectorColumnTargetWidth)
450 : null;
451 const [contentSizing, setContentSizing] = useState({
452 viewportWidth,
453 target: contentTargetWidth,
454 sidebarVisible: panes.primarySidebarVisible,
455 width: contentTargetWidth,
456 listPaneTarget: layout.listPaneWidth,
457 listPaneFloor: layout.listPaneWidth,
458 listPaneCeiling: layout.listPaneWidth,
459 revision: 0,
460 });
461 if (
462 Platform.OS === "android" &&
463 (contentSizing.viewportWidth !== viewportWidth ||
464 contentSizing.target !== contentTargetWidth ||
465 contentSizing.sidebarVisible !== panes.primarySidebarVisible ||
466 contentSizing.listPaneTarget !== layout.listPaneWidth)
467 ) {
468 const sameViewport = contentSizing.viewportWidth === viewportWidth;
469 const openingSidebar =
470 sameViewport && !contentSizing.sidebarVisible && panes.primarySidebarVisible;
471 // A book-posture hinge resizes the visible list pane instead of revealing it.
472 const resizingSidebar =
473 sameViewport &&
474 contentSizing.sidebarVisible &&
475 panes.primarySidebarVisible &&
476 contentSizing.listPaneTarget !== layout.listPaneWidth;
477 const keepWide =
478 (openingSidebar || resizingSidebar) &&
479 contentSizing.width !== null &&
480 contentTargetWidth !== null;
481 setContentSizing({
482 viewportWidth,
483 target: contentTargetWidth,
484 sidebarVisible: panes.primarySidebarVisible,
485 // Clip the wide navigator while the sidebar opens or widens, then reflow once at the
486 // end. Narrowing it first exposes an empty strip before the sidebar arrives.
487 width: keepWide
488 ? Math.max(contentSizing.width ?? 0, contentTargetWidth ?? 0)
489 : contentTargetWidth,
490 listPaneTarget: layout.listPaneWidth,
491 // While a hinge resizes the list, its width follows the pane edge within this span. A
492 // retarget mid-animation widens the span, since the edge is still somewhere inside it.
493 listPaneFloor: resizingSidebar
494 ? Math.min(contentSizing.listPaneFloor ?? 0, layout.listPaneWidth ?? 0)
495 : layout.listPaneWidth,
496 listPaneCeiling: resizingSidebar
497 ? Math.max(contentSizing.listPaneCeiling ?? 0, layout.listPaneWidth ?? 0)
498 : layout.listPaneWidth,
499 revision: contentSizing.revision + 1,
500 });
501 }
502 const settleContentWidth = (revision: number) => {
503 setContentSizing((current) =>
504 current.revision !== revision ||
505 (current.width === current.target &&
506 current.listPaneFloor === current.listPaneTarget &&
507 current.listPaneCeiling === current.listPaneTarget)
508 ? current
509 : {
510 ...current,
511 width: current.target,
512 listPaneFloor: current.listPaneTarget,
513 listPaneCeiling: current.listPaneTarget,
514 },
515 );
516 };
517 const listPaneFloor = contentSizing.listPaneFloor ?? 0;
518 const listPaneCeiling = contentSizing.listPaneCeiling ?? 0;
519 const contentSettledWidth = Platform.OS === "android" ? contentSizing.width : contentTargetWidth;
520 const contentRevision = contentSizing.revision;
521
522 const renderedSidebarWidth = useSharedValue(
523 panes.primarySidebarVisible ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0) : 0,
524 );
525 useEffect(() => {
526 if (nativeWorkspace) return;
527 const targetWidth = panes.primarySidebarVisible
528 ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
529 : 0;
530 renderedSidebarWidth.value = withTiming(targetWidth, WORKSPACE_PANE_TIMING, (finished) => {
531 if (finished && Platform.OS === "android") runOnJS(settleContentWidth)(contentRevision);
532 });
533 }, [
534 nativeWorkspace,
535 layout.listPaneWidth,
536 layout.listPaneGap,
537 panes.primarySidebarVisible,
538 renderedSidebarWidth,
539 settleContentWidth,
540 contentRevision,
541 ]);
542 // Showing or hiding the sidebar clips a fixed-width list. A hinge resize instead tracks the
543 // animated edge, so the header actions slide with it rather than jumping or being covered.
544 const listPaneGap = layout.listPaneGap ?? 0;
545 const listPaneAnimatedStyle = useAnimatedStyle(() => ({
546 width: Math.min(
547 listPaneCeiling,
548 Math.max(listPaneFloor, renderedSidebarWidth.value - listPaneGap),
549 ),
550 }));
551 const sidebarAnimatedStyle = useAnimatedStyle(() => ({
552 // Fading a UIKit glass ancestor can leave remounted header effects missing.
553 opacity: Platform.OS === "ios" ? 1 : Math.min(1, renderedSidebarWidth.value / 80),
554 width: renderedSidebarWidth.value,
555 }));
556
557 // The navigator (native header + markdown feed) lays out ONCE per pane toggle
558 // instead of re-measuring on every animation frame — the animating columns
559 // merely clip/reveal it over a matching background.
560 const renderedInspectorWidth = useSharedValue(inspectorColumnTargetWidth);
561 const renderedContentWidth = useDerivedValue(() =>
562 Math.max(0, viewportWidth - renderedSidebarWidth.value - renderedInspectorWidth.value),
563 );
564
565 const selectAndroidWorkspace = useAndroidWorkspaceSelection();
566 const handleSelectThread = (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 const contextValue = {
609 layout,
610 panes,
611 fileInspector,
612 primarySidebarSearchQuery,
613 selectThread: handleSelectThread,
614 activateAuxiliaryPaneRole,
615 registerWorkspaceInspector,
616 setPrimarySidebarSearchQuery,
617 showAuxiliaryPane,
618 toggleAuxiliaryPane,
619 togglePrimarySidebar,
620 setAuxiliaryPaneWidth,
621 };
622
623 if (nativeWorkspace) {
624 return (
625 <HomeListOptionsProvider
626 projectGroupingMode={projectGroupingMode}
627 savedFilters={props.savedThreadListFilters}
628 >
629 <AdaptiveWorkspaceContext value={contextValue}>
630 <NativeWorkspaceInspectorContext
631 value={{ render: workspaceInspector?.render, visible: inspectorColumnTargetWidth > 0 }}
632 >
633 {props.children}
634 </NativeWorkspaceInspectorContext>
635 </AdaptiveWorkspaceContext>
636 </HomeListOptionsProvider>
637 );
638 }
639 return (
640 <HomeListOptionsProvider
641 projectGroupingMode={projectGroupingMode}
642 savedFilters={props.savedThreadListFilters}
643 >
644 <AdaptiveWorkspaceContext.Provider value={contextValue}>
645 <WindowHingeContext value={windowHinge}>
646 <View
647 testID="adaptive-workspace-layout"
648 className={Platform.OS === "android" ? "flex-1 flex-row bg-header" : "flex-1 flex-row"}
649 >
650 <AndroidHingeObserver onChange={handleHingeChange} />
651 {shouldRenderPrimarySidebar && layout.listPaneWidth !== null ? (
652 <Animated.View
653 className="self-stretch overflow-hidden"
654 accessibilityElementsHidden={!panes.primarySidebarVisible}
655 collapsable={false}
656 importantForAccessibility={
657 panes.primarySidebarVisible ? "auto" : "no-hide-descendants"
658 }
659 pointerEvents={panes.primarySidebarVisible ? "auto" : "none"}
660 style={sidebarAnimatedStyle}
661 >
662 <Animated.View className="flex-1" style={listPaneAnimatedStyle}>
663 <RenderErrorBoundary
664 renderFallback={(fallback) => (
665 <RenderFailureView
666 {...fallback}
667 title="The sidebar couldn't be displayed"
668 exit={{ label: "Open settings", onPress: handleOpenSettings }}
669 />
670 )}
671 >
672 <AndroidWorkspaceSidebar
673 onRequestVisibility={revealPrimarySidebar}
674 selectedPullRequestKey={props.selectedPullRequestKey ?? null}
675 >
676 <AndroidHomeFabLayout sidebar onStartNewTask={handleStartNewTask}>
677 <ThreadNavigationSidebar
678 width={layout.listPaneWidth}
679 visible={panes.primarySidebarVisible}
680 onRequestVisibility={revealPrimarySidebar}
681 selectedThreadKey={selectedThreadKey}
682 onOpenSettings={handleOpenSettings}
683 onOpenEnvironmentSettings={handleOpenEnvironmentSettings}
684 onNewThreadInProject={handleNewThreadInProject}
685 onNewThreadOnBranch={handleNewThreadOnBranch}
686 onSelectThread={handleSelectThread}
687 onOpenThreadPullRequests={handleOpenThreadPullRequests}
688 onSearchQueryChange={setPrimarySidebarSearchQuery}
689 searchQuery={primarySidebarSearchQuery}
690 />
691 </AndroidHomeFabLayout>
692 </AndroidWorkspaceSidebar>
693 </RenderErrorBoundary>
694 </Animated.View>
695 </Animated.View>
696 ) : null}
697 <View
698 className={
699 Platform.OS === "android"
700 ? "flex-1 overflow-hidden bg-header"
701 : "flex-1 overflow-hidden bg-screen"
702 }
703 collapsable={false}
704 >
705 <View
706 collapsable={false}
707 style={
708 contentSettledWidth !== null
709 ? {
710 flex: 1,
711 width: contentSettledWidth,
712 }
713 : { flex: 1 }
714 }
715 >
716 <WorkspaceContentWidthContext
717 value={layout.usesSplitView ? renderedContentWidth : null}
718 >
719 {props.children}
720 </WorkspaceContentWidthContext>
721 </View>
722 </View>
723 <WorkspaceInspectorPane
724 pathname={props.pathname}
725 renderedInspectorWidth={renderedInspectorWidth}
726 active={workspaceInspector?.active ?? false}
727 panes={panes}
728 renderInspector={workspaceInspector?.render}
729 setAuxiliaryPaneWidth={setAuxiliaryPaneWidth}
730 onClosed={handleWorkspaceInspectorClosed}
731 />
732 </View>
733 </WindowHingeContext>
734 </AdaptiveWorkspaceContext.Provider>
735 </HomeListOptionsProvider>
736 );
737}