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): workspace tabs open with their last page instead of an e… · pingdotgg/t3code@120d79e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/mobile/src
    • App.tsx
    • Stack.tsx
    • features
      • home
        • HomeRouteScreen.tsx
      • keyboard
        • CommandPalette.tsx
      • layout
        • AdaptiveWorkspaceLayout.tsx
        • createWorkspaceStackNavigator.ios.tsx
      • workspace
        • WorkspaceNativeTabs.ios.tsx
        • WorkspaceRootScreen.tsx
        • WorkspaceSectionToolbar.tsx
        • WorkspaceSidebarTabs.ios.tsx
        • useSelectWorkspaceTab.ts
        • workspace-selection-store.ts
        • workspace-tab-navigation.test.ts
        • workspace-tab-navigation.ts
    • persistence
      • mobile-preferences.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/mobile/src/App.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/App.tsx
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordin
3232
import { VoiceInputProvider } from "./features/voice-input/VoiceInputProvider";
3333
import { GlobalVoiceInputControl } from "./features/voice-input/GlobalVoiceInputControl";
3434
import { restoreSettingsLinkState } from "./features/settings/settings-navigation";
35+
import {
36+
hydrateWorkspaceSelections,
37+
launchWorkspaceURL,
38+
recordWorkspaceSelections,
39+
} from "./features/workspace/workspace-selection-store";
3540
import { NativeLayoutMetricsProvider } from "./native/native-layout-metrics";
3641

3742
import "../global.css";
@@ -41,11 +46,13 @@ if (process.env.EXPO_PUBLIC_SHOWCASE === "1") {
4146
}
4247

4348
void SplashScreen.preventAutoHideAsync().catch(() => {});
49+
void hydrateWorkspaceSelections();
4450

4551
const appLinking = {
4652
prefixes: [Linking.createURL("/"), "t3code://", "t3code-dev://", "t3code-preview://"],
4753
config: { initialRouteName: "Home" },
4854
filter: shouldHandleAppLink,
55+
getInitialURL: async () => (await Linking.getInitialURL()) ?? (await launchWorkspaceURL()),
4956
getStateFromPath: (path: string, options: Parameters<typeof getStateFromPath>[1]) =>
5057
restoreSettingsLinkState(restoreDraftLinkState(getStateFromPath(path, options), path)),
5158
};
@@ -108,7 +115,11 @@ function AppContent() {
108115
<GlobalVoiceInputControl>
109116
<NativeLayoutMetricsProvider>
110117
<IncomingShareProvider>
111-
<Navigation linking={appLinking} theme={navigationTheme} />
118+
<Navigation
119+
linking={appLinking}
120+
theme={navigationTheme}
121+
onStateChange={recordWorkspaceSelections}
122+
/>
112123
</IncomingShareProvider>
113124
<Dialog.Host />
114125
<ThreadArrangementHost />
Collapse file

‎apps/mobile/src/Stack.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/Stack.tsx
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ import { SettingsNotificationsRouteScreen } from "./features/settings/SettingsNo
124124
import { SettingsRouteScreen } from "./features/settings/SettingsRouteScreen";
125125
import { SettingsThreadsRouteScreen } from "./features/settings/SettingsThreadsRouteScreen";
126126
import { SettingsEnvironmentFilterProvider } from "./features/settings/settings-environment-filter";
127-
import { openSettings, settingsOpenIn } from "./features/settings/settings-navigation";
127+
import { settingsOpenIn } from "./features/settings/settings-navigation";
128128
import { ShowcaseCaptureCoordinator } from "./features/showcase/ShowcaseCaptureCoordinator";
129129
import {
130130
SettingsLegalDocumentCloseHeaderButton,
@@ -143,6 +143,7 @@ import { nativeHeaderScrollEdgeEffects } from "./native/StackHeader";
143143
import { HORIZONTAL_FORM_SHEET_OPTIONS, formSheetDetents } from "./native/sheet-surface";
144144
import { useThreadOutboxDrain } from "./state/use-thread-outbox-drain";
145145
import { useComposerAttachmentUploadWorker } from "./state/composer-attachment-uploads";
146+
import { useSelectWorkspaceTab } from "./features/workspace/useSelectWorkspaceTab";
146147

147148
const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
148149

@@ -1045,10 +1046,11 @@ function GuardedScreenLayout(props: {
10451046

10461047
function ScreenRenderFallback(props: RenderFailureProps & { readonly routeName: string }) {
10471048
const navigation = useNavigation();
1049+
const selectTab = useSelectWorkspaceTab();
10481050
const exit = navigation.canGoBack()
10491051
? { label: "Go back", onPress: () => navigation.goBack() }
10501052
: props.routeName === "Home"
1051-
? { label: "Open settings", onPress: () => openSettings(navigation) }
1053+
? { label: "Open settings", onPress: () => selectTab("settings") }
10521054
: { label: "Return home", onPress: () => navigation.dispatch(StackActions.replace("Home")) };
10531055

10541056
return <RenderFailureView {...props} exit={exit} />;
Collapse file

‎apps/mobile/src/features/home/HomeRouteScreen.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/home/HomeRouteScreen.tsx
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { useThreadListActions } from "./useThreadListActions";
3535
import { getConnectionAwareBrandHeaderOptions } from "./WorkspaceConnectionTitle";
3636
import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
3737
import { openSettings } from "../settings/settings-navigation";
38+
import { useSelectWorkspaceTab } from "../workspace/useSelectWorkspaceTab";
3839

3940
export function HomeRouteScreen() {
4041
const { width: windowWidth } = useWindowDimensions();
@@ -55,6 +56,7 @@ export function HomeRouteScreen() {
5556
const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState();
5657
const { savedConnectionsById } = useSavedRemoteConnections();
5758
const navigation = useNavigation();
59+
const selectTab = useSelectWorkspaceTab();
5860
const workspace = useWorkspaceTabs();
5961
const [localSearchQuery, setLocalSearchQuery] = useState("");
6062
const searchQuery =
@@ -229,7 +231,7 @@ export function HomeRouteScreen() {
229231
onEnvironmentChange={setSelectedEnvironmentId}
230232
onProjectChange={setSelectedProjectKey}
231233
onOpenEnvironments={() => openSettings(navigation, "SettingsEnvironments")}
232-
onOpenSettings={() => openSettings(navigation, "Settings")}
234+
onOpenSettings={() => selectTab("settings")}
233235
onSearchQueryChange={setSearchQuery}
234236
onStartNewTask={startNewTask}
235237
/>
@@ -252,7 +254,7 @@ export function HomeRouteScreen() {
252254
onRegenerateThreadTitle={regenerateThreadTitle}
253255
onEnvironmentChange={setSelectedEnvironmentId}
254256
onProjectChange={setSelectedProjectKey}
255-
onOpenSettings={() => openSettings(navigation, "Settings")}
257+
onOpenSettings={() => selectTab("settings")}
256258
onSearchQueryChange={setSearchQuery}
257259
onSelectThread={handleSelectThread}
258260
onSelectPendingTask={openPendingTask}
Collapse file

‎apps/mobile/src/features/keyboard/CommandPalette.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/keyboard/CommandPalette.tsx
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { parseActiveThreadPath, type HardwareKeyboardCommand } from "./hardwareK
4444
import { threadJumpIndex } from "./threadKeyboardShortcuts";
4545
import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
4646
import { openSettings } from "../settings/settings-navigation";
47+
import { useSelectWorkspaceTab } from "../workspace/useSelectWorkspaceTab";
4748

4849
const PALETTE_COMMANDS: ReadonlyArray<HardwareKeyboardCommand> = [
4950
"commandPalette",
@@ -156,6 +157,7 @@ export function CommandPalette(props: {
156157
readonly onCommand: (command: HardwareKeyboardCommand) => void;
157158
}) {
158159
const navigation = useNavigation();
160+
const selectTab = useSelectWorkspaceTab();
159161
const { themeVariables } = useAppearancePreferences();
160162
const { selectThread, selectThreadRoute } = useAdaptiveWorkspaceLayout();
161163
const runCommand = props.onCommand;
@@ -219,7 +221,7 @@ export function CommandPalette(props: {
219221
kind: "action",
220222
title: "Open settings",
221223
searchTerms: ["preferences", "configuration"],
222-
run: () => openSettings(navigation, "Settings"),
224+
run: () => selectTab("settings"),
223225
},
224226
{
225227
key: "appearance",
Collapse file

‎apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+13-3Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ import { AndroidHingeObserver } from "../../native/AndroidHingeObserver";
9494
import { WindowHingeContext } from "../../native/window-hinge-context";
9595
import { useAndroidWorkspaceRoot } from "../workspace/AndroidWorkspaceTabsProvider";
9696
import { openSettings } from "../settings/settings-navigation";
97+
import { resetRootStack } from "../../lib/root-stack-reset";
98+
import { currentWorkspaceSelections } from "../workspace/workspace-selection-store";
99+
import { workspaceTabNavigationState } from "../workspace/workspace-tab-navigation";
97100

98101
export { useAdaptiveWorkspaceLayout };
99102

@@ -460,9 +463,16 @@ function AdaptiveWorkspaceLayoutContent(
460463
}
461464
setSupplementaryPanePreferredWidth(nextWidth);
462465
};
463-
const handleOpenSettings = () => {
464-
openSettings(navigation, "Settings");
465-
};
466+
// This layout provides the context useSelectWorkspaceTab reads, so it builds the state itself.
467+
const handleOpenSettings = () =>
468+
resetRootStack(navigation, (state) =>
469+
workspaceTabNavigationState(
470+
state,
471+
"settings",
472+
currentWorkspaceSelections(),
473+
Platform.OS === "ios" && layout.usesSplitView,
474+
),
475+
);
466476

467477
const selectAndroidWorkspace = useAndroidWorkspaceSelection();
468478
const deferredThreadSelection = useMemo(() => createDeferredNavigation(), []);
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
+27-15Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
createNavigatorFactory,
33
NavigationContext,
44
NavigationRouteContext,
5-
StackActions,
65
StackRouter,
76
useNavigationBuilder,
87
type NavigatorTypeBagBase,
@@ -29,6 +28,9 @@ import { WorkspaceTabsProvider, useWorkspaceTabs } from "../workspace/WorkspaceT
2928
import { WorkspaceNativeTabs } from "../workspace/WorkspaceNativeTabs.ios";
3029
import { workspaceUsesColumns } from "../workspace/workspace-tabs-state";
3130
import { isSettingsRoute, settingsOpenIn } from "../settings/settings-navigation";
31+
import { resetRootStack } from "../../lib/root-stack-reset";
32+
import { currentWorkspaceSelections } from "../workspace/workspace-selection-store";
33+
import { workspaceTabNavigationState } from "../workspace/workspace-tab-navigation";
3234
import { useWorkspaceSidebarHeaderItem } from "./useWorkspaceSidebarHeaderItem";
3335
import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
3436

@@ -212,16 +214,6 @@ function WorkspaceColumns(
212214
const workspaceTabs = useWorkspaceTabs();
213215
const selectedTab = workspaceTabs?.state.selectedTab;
214216
const settingsOpen = workspaceTabs?.settingsOpen ?? false;
215-
// A split view can't give the list the whole width, so with columns side by side Settings
216-
// opens a first page beside its list, like the system Settings app.
217-
const settingsNeedsPage =
218-
settingsOpen &&
219-
layout.usesSplitView &&
220-
!layout.primarySidebarOverlaysContent &&
221-
props.detail.length === 0;
222-
useEffect(() => {
223-
if (settingsNeedsPage) props.navigation.dispatch(StackActions.push("SettingsEnvironments"));
224-
}, [settingsNeedsPage, props.navigation]);
225217
const openNewTask = startNewTask;
226218
// The cover detail rail needs room for thread tools above the fixed tabs.
227219
// The unfolded Duo keeps compose in its detail bar.
@@ -311,6 +303,30 @@ function WorkspaceColumns(
311303
}}
312304
onExpand={() => {
313305
collapsed.current = false;
306+
// Native callbacks can outlive the render that created them, so decide from the live
307+
// router state: expanding gives the tab a detail column, filled with its last page.
308+
const live = props.navigation.getState();
309+
const isOverlay = (route: { readonly key: string }) => {
310+
const presentation = props.descriptors[route.key]?.options.presentation;
311+
return presentation !== undefined && presentation !== "card";
312+
};
313+
const routes = live.routes.slice(0, live.index + 1);
314+
const firstOverlay = routes.findIndex(isOverlay);
315+
const workspaceRoutes = firstOverlay < 0 ? routes : routes.slice(0, firstOverlay);
316+
if (workspaceRoutes.some((route) => route.name !== "Home" && route.name !== "Settings"))
317+
return;
318+
const settings = workspaceRoutes.some((route) => route.name === "Settings");
319+
const tab = (["threads", "pullRequests", "usage"] as const).find((candidate) =>
320+
workspaceTabs?.isTabActive(candidate),
321+
);
322+
resetRootStack(props.navigation, (state) =>
323+
workspaceTabNavigationState(
324+
state,
325+
settings ? "settings" : (tab ?? "threads"),
326+
currentWorkspaceSelections(),
327+
true,
328+
),
329+
);
314330
}}
315331
preferredDisplayMode={
316332
// UIKit applies the mode as a collapsed split expands, before the new width reaches JS, so a
@@ -452,10 +468,6 @@ function WorkspaceStackView(props: ViewProps & { readonly nativeColumns: boolean
452468
!layout.usesSplitView &&
453469
(metrics?.verticalBarEdge ?? "none") === "none"
454470
}
455-
onSelect={() => {
456-
if (props.state.index > 0)
457-
props.navigation.dispatch({ type: "POP_TO_TOP", target: props.state.key });
458-
}}
459471
>
460472
{props.nativeColumns && !workspacePage ? (
461473
<WorkspaceColumns
Collapse file

‎apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx
+5-16Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { useNavigation } from "@react-navigation/native";
21
import {
32
WORKSPACE_TAB_LABELS,
43
NAVIGATION_TAB_ICONS,
54
useEnabledNavigationTabs,
65
} from "./navigation-tabs";
76
import { useCallback, useMemo, useState, type ReactNode } from "react";
8-
import { Keyboard, View, useWindowDimensions, type NativeSyntheticEvent } from "react-native";
7+
import { View, useWindowDimensions, type NativeSyntheticEvent } from "react-native";
98
import {
109
Tabs,
1110
type TabSelectedEvent,
@@ -26,7 +25,7 @@ import { useControlTheme } from "../../components/ui/useControlTheme";
2625
import { useDeviceType } from "../../native/native-layout-metrics";
2726
import { WorkspaceSidebarTabs } from "./WorkspaceSidebarTabs";
2827
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
29-
import { openSettings } from "../settings/settings-navigation";
28+
import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
3029

3130
const PULL_REQUEST_ICON = require("../../../assets/icons/pull-request.png");
3231

@@ -61,13 +60,12 @@ function RetainedWorkspaceTab(props: {
6160
export function WorkspaceNativeTabs(props: {
6261
readonly children: ReactNode;
6362
readonly hidden: boolean;
64-
readonly onSelect: () => void;
6563
}) {
6664
const workspace = useWorkspaceTabs()!;
6765
const order = useEnabledNavigationTabs();
6866
const primaryTabs = order.slice(0, 4);
6967
const overflow = order[4];
70-
const navigation = useNavigation();
68+
const selectTab = useSelectWorkspaceTab();
7169
const [provenance, setProvenance] = useState(0);
7270
const systemTabBar = useSystemWorkspaceTabBar();
7371
const deviceType = useDeviceType();
@@ -99,9 +97,7 @@ export function WorkspaceNativeTabs(props: {
9997
onTabSelectionPrevented={({
10098
nativeEvent,
10199
}: NativeSyntheticEvent<TabSelectionPreventedEvent>) => {
102-
if (nativeEvent.preventedScreenKey === "settings") {
103-
openSettings(navigation, "Settings");
104-
}
100+
if (nativeEvent.preventedScreenKey === "settings") selectTab("settings");
105101
}}
106102
onTabSelectionRejected={({
107103
nativeEvent,
@@ -113,14 +109,7 @@ export function WorkspaceNativeTabs(props: {
113109
if (nativeEvent.actionOrigin === "programmatic-js") return;
114110
const tab = workspaceTabForNativeSlot(primaryTabs, nativeEvent.selectedScreenKey);
115111
// UIKit sends reselects here even when preventNativeSelection is enabled.
116-
if (tab === "settings") {
117-
openSettings(navigation, "Settings");
118-
return;
119-
}
120-
if (!tab) return;
121-
Keyboard.dismiss();
122-
props.onSelect();
123-
workspace.dispatch({ type: "select", tab });
112+
if (tab) selectTab(tab);
124113
}}
125114
>
126115
{NATIVE_WORKSPACE_TAB_SLOTS.map((slot, index) => {
Collapse file

‎apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
useSystemWorkspaceTabBar,
4747
} from "./useSystemWorkspaceTabBar";
4848
import { openSettings } from "../settings/settings-navigation";
49+
import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
4950

5051
const TAB_TITLES = WORKSPACE_TAB_LABELS;
5152

@@ -72,6 +73,7 @@ function WorkspaceRootTitle(props: {
7273

7374
function WorkspaceRootContent() {
7475
const navigation = useNavigation();
76+
const selectTab = useSelectWorkspaceTab();
7577
const { width: windowWidth } = useWindowDimensions();
7678
const { layout, startNewTask } = useAdaptiveWorkspaceLayout();
7779
const primaryColumn = use(NativePrimaryColumnContext);
@@ -186,7 +188,7 @@ function WorkspaceRootContent() {
186188
{
187189
accessibilityLabel: "Settings",
188190
icon: "gearshape",
189-
onPress: () => openSettings(navigation, "Settings"),
191+
onPress: () => selectTab("settings"),
190192
},
191193
]}
192194
/>
Collapse file

‎apps/mobile/src/features/workspace/WorkspaceSectionToolbar.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/workspace/WorkspaceSectionToolbar.tsx
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
import { useWorkspaceTabs } from "./WorkspaceTabsContext";
1313
import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
1414
import { useCompactWorkspaceTabs, useSidebarWorkspaceTabs } from "./useSystemWorkspaceTabBar";
15-
import { openSettings } from "../settings/settings-navigation";
1615

1716
const PULL_REQUEST_ICON = require("../../../assets/icons/pull-request.png");
1817

@@ -50,7 +49,7 @@ export function WorkspaceTabToolbarButtons() {
5049
accessibilityLabel="Settings"
5150
icon="gearshape"
5251
tintColor={selected === "settings" ? selectedTint : undefined}
53-
onPress={() => openSettings(navigation, "Settings")}
52+
onPress={() => selectTab("settings")}
5453
/>
5554
</>
5655
);
Collapse file

‎apps/mobile/src/features/workspace/WorkspaceSidebarTabs.ios.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/workspace/WorkspaceSidebarTabs.ios.tsx
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { useControlTheme } from "../../components/ui/useControlTheme";
66
import { useNavigationTabOrder, useHiddenNavigationTabs } from "./navigation-tabs";
77
import { useWorkspaceTabs } from "./WorkspaceTabsContext";
88
import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
9-
import { openSettings } from "../settings/settings-navigation";
109

1110
const NativeSidebarTabBar = requireNativeView<
1211
ViewProps & {
@@ -52,7 +51,7 @@ export function WorkspaceSidebarTabs(props: {
5251
onCompose={() => props.onNewTask?.()}
5352
onSelectionChange={({ nativeEvent }) => {
5453
const tab = tabs.find((candidate) => candidate === nativeEvent.tab);
55-
if (tab === "settings") openSettings(navigation, "Settings");
54+
if (tab === "settings") selectTab("settings");
5655
else if (tab) selectTab(tab);
5756
}}
5857
// Keep the host stable while UIKit updates the bars' intrinsic size and safe area together.

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.