GeezerVison is showing github.com — fix(mobile): folded Duo opens a thread picked while Back is still ani… · patroza/t3code@de3ec23
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -20,15 +20,7 @@ import { | 20 | 20 | type NativeStackNavigatorProps, | 21 | 21 | type NativeStackTypeBag, | 22 | 22 | } 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"; | 32 | 24 | import { withKnownPullRequestSummary } from "../../state/use-thread-pr"; | 33 | 25 | import { | 34 | 26 | currentWorkspaceSelections, | @@ -52,6 +44,7 @@ import { selectedIssueKeyOf } from "../issues/issueParams"; | 52 | 44 | import { isSettingsRoute, settingsOpenIn } from "../settings/settings-navigation"; | 53 | 45 | import { workspaceRoutesOf } from "./workspace-overlay-routes"; | 54 | 46 | import { setNativelyPoppingWorkspaceRoute } from "./workspace/workspace-detail-selection"; | | 47 | +import { useCollapsedSplitColumn } from "./useCollapsedSplitColumn"; | 55 | 48 | import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics"; | 56 | 49 |
| 57 | 50 | import { useAdaptiveWorkspaceLayout, useWorkspacePaneState } from "./AdaptiveWorkspaceLayout"; | @@ -73,12 +66,10 @@ import { PaneContext } from "../../components/ui/Pane"; | 73 | 66 | import { useWorkspaceSidebarHeaderItem } from "./useWorkspaceSidebarHeaderItem"; | 74 | 67 | import type { AppNativeStackNavigationOptions } from "../../native/StackHeader"; | 75 | 68 | import { | 76 | | - collapsedSplitTransition, | 77 | 69 | nativeWorkspacePopAction, | 78 | 70 | projectWorkspaceStack, | 79 | 71 | partitionStackPresentations, | 80 | 72 | reconcileStackScreens, | 81 | | - type CollapsedSplitColumn, | 82 | 73 | isPresentedRoute, | 83 | 74 | } from "../../native/workspace-stack-projection"; | 84 | 75 | import { | @@ -290,11 +281,16 @@ function WorkspaceColumns( | 290 | 281 | const hideInspector = () => { | 291 | 282 | if (inspector.visible) toggleAuxiliaryPane(); | 292 | 283 | }; | 293 | | - const hostRef = useRef<SplitHostCommands>(null); | 294 | 284 | const activeDetailKey = props.detail.at(-1)?.key; | 295 | 285 | 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 | + }); | 298 | 294 | const threadParams = props.detail.findLast((route) => route.name === "Thread")?.params; | 299 | 295 | const pullRequestParams = props.detail.findLast(isPullRequestRoute)?.params; | 300 | 296 | const selectedPullRequestKey = | @@ -333,28 +329,6 @@ function WorkspaceColumns( | 333 | 329 | if (action) props.navigation.dispatch(action); | 334 | 330 | } | 335 | 331 | }; | 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]); | 358 | 332 |
| 359 | 333 | const primary = props.descriptors[props.primary.key]; | 360 | 334 | if (!primary) return null; | @@ -372,14 +346,9 @@ function WorkspaceColumns( | 372 | 346 | } | 373 | 347 | primaryBackgroundStyle={deviceType === "pad" ? "none" : "default"} | 374 | 348 | topColumnForCollapsing={compactColumn} | 375 | | - onCollapse={() => { | 376 | | - collapsed.current = true; | 377 | | - collapsedColumn.current = { visible: compactColumn, leaving: null }; | 378 | | - setNativelyPoppingWorkspaceRoute(null); | 379 | | - }} | | 349 | + onCollapse={onCollapse} | 380 | 350 | onExpand={() => { | 381 | | - collapsed.current = false; | 382 | | - setNativelyPoppingWorkspaceRoute(null); | | 351 | + onExpand(); | 383 | 352 | // Native callbacks can outlive the render that created them, so decide from the live | 384 | 353 | // router state. An expanded split has columns, so its tab gets a page beside the list. | 385 | 354 | const live = props.navigation.getState(); | @@ -434,7 +403,7 @@ function WorkspaceColumns( | 434 | 403 | selectedPullRequestKey={selectedPullRequestKey} | 435 | 404 | selectedIssueKey={selectedIssueKey} | 436 | 405 | onDismiss={handleNativeDismiss} | 437 | | - onAppearance={followCollapsedSplit} | | 406 | + onAppearance={followAppearance} | 438 | 407 | navigation={props.navigation} | 439 | 408 | /> | 440 | 409 | </Stack.Host> | @@ -470,7 +439,7 @@ function WorkspaceColumns( | 470 | 439 | attached={props.detail.some((current) => current.key === route.key)} | 471 | 440 | animatesPush={!shownPages.keys.has(route.key)} | 472 | 441 | onDismiss={handleNativeDismiss} | 473 | | - onAppearance={followCollapsedSplit} | | 442 | + onAppearance={followAppearance} | 474 | 443 | onCompose={isPullRequestRoute(route) ? undefined : detailCompose} | 475 | 444 | navigation={props.navigation} | 476 | 445 | /> | |
Collapse file Copy file name to clipboard +58Lines changed: 58 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboard +62Lines changed: 62 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboardExpand all lines: apps/mobile/vite.config.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -48,6 +48,7 @@ const reactTests = [ | 48 | 48 | "src/components/ComposerEditor.ios.test.tsx", | 49 | 49 | "src/native/V5StackHeader.ios.test.tsx", | 50 | 50 | "src/native/createV5StackNavigator.ios.test.tsx", | | 51 | + "src/features/layout/useCollapsedSplitColumn.test.tsx", | 51 | 52 | "src/native/useRetryingImageSource.test.tsx", | 52 | 53 | "src/state/queries.debounce.test.tsx", | 53 | 54 | "src/state/use-selected-thread-git-state.test.tsx", | |
|