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

AdaptiveWorkspaceLayout.tsx

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