GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mobile): folded Duo opens a thread picked while Back is still ani… · patroza/t3code@de3ec23

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/mobile
    • src/features/layout
      • createWorkspaceStackNavigator.ios.tsx
      • useCollapsedSplitColumn.test.tsx
      • useCollapsedSplitColumn.ts
    • vite.config.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
+14-45Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,7 @@ import {
2020
type NativeStackNavigatorProps,
2121
type NativeStackTypeBag,
2222
} from "@react-navigation/native-stack";
23-
import {
24-
Fragment,
25-
use,
26-
useEffect,
27-
useRef,
28-
useState,
29-
type ComponentProps,
30-
type ReactNode,
31-
} from "react";
23+
import { Fragment, use, useRef, useState, type ComponentProps, type ReactNode } from "react";
3224
import { withKnownPullRequestSummary } from "../../state/use-thread-pr";
3325
import {
3426
currentWorkspaceSelections,
@@ -52,6 +44,7 @@ import { selectedIssueKeyOf } from "../issues/issueParams";
5244
import { isSettingsRoute, settingsOpenIn } from "../settings/settings-navigation";
5345
import { workspaceRoutesOf } from "./workspace-overlay-routes";
5446
import { setNativelyPoppingWorkspaceRoute } from "./workspace/workspace-detail-selection";
47+
import { useCollapsedSplitColumn } from "./useCollapsedSplitColumn";
5548
import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
5649

5750
import { useAdaptiveWorkspaceLayout, useWorkspacePaneState } from "./AdaptiveWorkspaceLayout";
@@ -73,12 +66,10 @@ import { PaneContext } from "../../components/ui/Pane";
7366
import { useWorkspaceSidebarHeaderItem } from "./useWorkspaceSidebarHeaderItem";
7467
import type { AppNativeStackNavigationOptions } from "../../native/StackHeader";
7568
import {
76-
collapsedSplitTransition,
7769
nativeWorkspacePopAction,
7870
projectWorkspaceStack,
7971
partitionStackPresentations,
8072
reconcileStackScreens,
81-
type CollapsedSplitColumn,
8273
isPresentedRoute,
8374
} from "../../native/workspace-stack-projection";
8475
import {
@@ -290,11 +281,16 @@ function WorkspaceColumns(
290281
const hideInspector = () => {
291282
if (inspector.visible) toggleAuxiliaryPane();
292283
};
293-
const hostRef = useRef<SplitHostCommands>(null);
294284
const activeDetailKey = props.detail.at(-1)?.key;
295285
const compactColumn = activeDetailKey ? "secondary" : "primary";
296-
const collapsed = useRef(!layout.usesSplitView);
297-
const collapsedColumn = useRef<CollapsedSplitColumn>({ visible: compactColumn, leaving: null });
286+
const hostRef = useRef<SplitHostCommands>(null);
287+
const { followAppearance, onCollapse, onExpand } = useCollapsedSplitColumn({
288+
hostRef,
289+
usesSplitView: layout.usesSplitView,
290+
compactColumn,
291+
primaryKey: props.primary.key,
292+
navigation: props.navigation,
293+
});
298294
const threadParams = props.detail.findLast((route) => route.name === "Thread")?.params;
299295
const pullRequestParams = props.detail.findLast(isPullRequestRoute)?.params;
300296
const selectedPullRequestKey =
@@ -333,28 +329,6 @@ function WorkspaceColumns(
333329
if (action) props.navigation.dispatch(action);
334330
}
335331
};
336-
const followCollapsedSplit = (
337-
type: "willAppear" | "didAppear" | "willDisappear" | "didDisappear",
338-
key: string,
339-
) => {
340-
if (!collapsed.current || layout.usesSplitView) return;
341-
const transition = collapsedSplitTransition(
342-
collapsedColumn.current,
343-
{ type, key },
344-
props.navigation.getState(),
345-
props.primary.key,
346-
);
347-
collapsedColumn.current = transition.column;
348-
setNativelyPoppingWorkspaceRoute(transition.column.leaving);
349-
if (transition.pop) props.navigation.dispatch(transition.pop);
350-
};
351-
352-
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- tells the native split host which column to show while collapsed
353-
useEffect(() => {
354-
if (layout.usesSplitView || collapsedColumn.current.visible === compactColumn) return;
355-
collapsedColumn.current = { ...collapsedColumn.current, visible: compactColumn };
356-
hostRef.current?.show(compactColumn);
357-
}, [compactColumn, layout.usesSplitView]);
358332

359333
const primary = props.descriptors[props.primary.key];
360334
if (!primary) return null;
@@ -372,14 +346,9 @@ function WorkspaceColumns(
372346
}
373347
primaryBackgroundStyle={deviceType === "pad" ? "none" : "default"}
374348
topColumnForCollapsing={compactColumn}
375-
onCollapse={() => {
376-
collapsed.current = true;
377-
collapsedColumn.current = { visible: compactColumn, leaving: null };
378-
setNativelyPoppingWorkspaceRoute(null);
379-
}}
349+
onCollapse={onCollapse}
380350
onExpand={() => {
381-
collapsed.current = false;
382-
setNativelyPoppingWorkspaceRoute(null);
351+
onExpand();
383352
// Native callbacks can outlive the render that created them, so decide from the live
384353
// router state. An expanded split has columns, so its tab gets a page beside the list.
385354
const live = props.navigation.getState();
@@ -434,7 +403,7 @@ function WorkspaceColumns(
434403
selectedPullRequestKey={selectedPullRequestKey}
435404
selectedIssueKey={selectedIssueKey}
436405
onDismiss={handleNativeDismiss}
437-
onAppearance={followCollapsedSplit}
406+
onAppearance={followAppearance}
438407
navigation={props.navigation}
439408
/>
440409
</Stack.Host>
@@ -470,7 +439,7 @@ function WorkspaceColumns(
470439
attached={props.detail.some((current) => current.key === route.key)}
471440
animatesPush={!shownPages.keys.has(route.key)}
472441
onDismiss={handleNativeDismiss}
473-
onAppearance={followCollapsedSplit}
442+
onAppearance={followAppearance}
474443
onCompose={isPullRequestRoute(route) ? undefined : detailCompose}
475444
navigation={props.navigation}
476445
/>
Collapse file

‎apps/mobile/src/features/layout/useCollapsedSplitColumn.test.tsx‎

Copy file name to clipboard
+58Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { NavigationState } from "@react-navigation/native";
2+
import { act } from "react";
3+
import { createRoot } from "react-dom/client";
4+
import { expect, it, vi } from "vite-plus/test";
5+
6+
vi.mock("./workspace/workspace-detail-selection", () => ({
7+
setNativelyPoppingWorkspaceRoute: () => {},
8+
}));
9+
10+
import { useCollapsedSplitColumn } from "./useCollapsedSplitColumn";
11+
12+
const home = { key: "home", name: "Home" };
13+
const left = { key: "thread-a", name: "Thread" };
14+
const picked = { key: "thread-b", name: "Thread" };
15+
16+
function routerState(routes: ReadonlyArray<{ key: string; name: string }>) {
17+
return { key: "stack", index: routes.length - 1, routes } as unknown as NavigationState;
18+
}
19+
20+
it("shows a thread picked while folded Back is still revealing the list", () => {
21+
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
22+
let state = routerState([home, left]);
23+
const show = vi.fn();
24+
const navigation = { getState: () => state, dispatch: vi.fn() };
25+
const hostRef = { current: { show } as never };
26+
let split: ReturnType<typeof useCollapsedSplitColumn> | undefined;
27+
function Columns() {
28+
split = useCollapsedSplitColumn({
29+
hostRef,
30+
usesSplitView: false,
31+
compactColumn: state.index > 0 ? "secondary" : "primary",
32+
primaryKey: home.key,
33+
navigation,
34+
});
35+
return null;
36+
}
37+
const root = createRoot(document.createElement("div"));
38+
const render = () => act(() => root.render(<Columns />));
39+
try {
40+
render();
41+
act(() => split!.followAppearance("willDisappear", left.key));
42+
act(() => split!.followAppearance("willAppear", home.key));
43+
// The list is tappable from willAppear, so the next thread is picked before didAppear.
44+
state = routerState([home, left, picked]);
45+
render();
46+
act(() => split!.followAppearance("didAppear", home.key));
47+
expect(navigation.dispatch).toHaveBeenCalledWith(
48+
expect.objectContaining({ type: "POP", source: left.key }),
49+
);
50+
// Back's pop keeps the picked thread, so the compact column stays "secondary" across renders.
51+
state = routerState([home, picked]);
52+
render();
53+
expect(show).toHaveBeenLastCalledWith("secondary");
54+
} finally {
55+
act(() => root.unmount());
56+
vi.unstubAllGlobals();
57+
}
58+
});
Collapse file

‎apps/mobile/src/features/layout/useCollapsedSplitColumn.ts‎

Copy file name to clipboard
+62Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import type { NavigationAction, NavigationState } from "@react-navigation/native";
2+
import { useEffect, useRef, type RefObject } from "react";
3+
import type { SplitHostCommands } from "react-native-screens";
4+
import {
5+
collapsedSplitTransition,
6+
type CollapsedSplitColumn,
7+
} from "../../native/workspace-stack-projection";
8+
import { setNativelyPoppingWorkspaceRoute } from "./workspace/workspace-detail-selection";
9+
10+
type Appearance = "willAppear" | "didAppear" | "willDisappear" | "didDisappear";
11+
12+
/** Keeps the column a collapsed split shows in step with the router's active detail. */
13+
export function useCollapsedSplitColumn(input: {
14+
readonly hostRef: RefObject<SplitHostCommands | null>;
15+
readonly usesSplitView: boolean;
16+
readonly compactColumn: CollapsedSplitColumn["visible"];
17+
readonly primaryKey: string;
18+
readonly navigation: {
19+
readonly getState: () => Pick<NavigationState, "key" | "index" | "routes">;
20+
readonly dispatch: (action: NavigationAction) => void;
21+
};
22+
}) {
23+
const { hostRef, usesSplitView, compactColumn } = input;
24+
const collapsed = useRef(!usesSplitView);
25+
const column = useRef<CollapsedSplitColumn>({ visible: compactColumn, leaving: null });
26+
27+
const showCompactColumn = () => {
28+
if (usesSplitView || column.current.visible === compactColumn) return;
29+
column.current = { ...column.current, visible: compactColumn };
30+
hostRef.current?.show(compactColumn);
31+
};
32+
// Every commit, not only when compactColumn changes: a thread picked while folded Back reveals
33+
// the list survives Back's pop, so the router keeps a detail while UIKit shows the list.
34+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- tells the native split host which column to show while collapsed
35+
useEffect(showCompactColumn);
36+
37+
return {
38+
followAppearance: (type: Appearance, key: string) => {
39+
if (!collapsed.current || usesSplitView) return;
40+
const transition = collapsedSplitTransition(
41+
column.current,
42+
{ type, key },
43+
input.navigation.getState(),
44+
input.primaryKey,
45+
);
46+
column.current = transition.column;
47+
setNativelyPoppingWorkspaceRoute(transition.column.leaving);
48+
// A pop re-renders and the effect above follows it; without one, nothing would re-render.
49+
if (transition.pop) input.navigation.dispatch(transition.pop);
50+
else showCompactColumn();
51+
},
52+
onCollapse: () => {
53+
collapsed.current = true;
54+
column.current = { visible: compactColumn, leaving: null };
55+
setNativelyPoppingWorkspaceRoute(null);
56+
},
57+
onExpand: () => {
58+
collapsed.current = false;
59+
setNativelyPoppingWorkspaceRoute(null);
60+
},
61+
};
62+
}
Collapse file

‎apps/mobile/vite.config.ts‎

Copy file name to clipboardExpand all lines: apps/mobile/vite.config.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const reactTests = [
4848
"src/components/ComposerEditor.ios.test.tsx",
4949
"src/native/V5StackHeader.ios.test.tsx",
5050
"src/native/createV5StackNavigator.ios.test.tsx",
51+
"src/features/layout/useCollapsedSplitColumn.test.tsx",
5152
"src/native/useRetryingImageSource.test.tsx",
5253
"src/state/queries.debounce.test.tsx",
5354
"src/state/use-selected-thread-git-state.test.tsx",

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.