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

AdaptiveWorkspaceLayout.tsx

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