Skip to content

Commit 6e3064f

Browse files
refactor(mobile): the share inbox is a module store, presented from navigation state
The incoming share inbox lived in a React provider that wrapped the navigation container: four effects loaded it, subscribed to app resume, tracked mount state, and turned an error state into an alert. A fifth effect in the root stack layout re-ran on every navigation state change to decide whether to open the pending share. The inbox is now a module store. App.tsx starts it once at module scope (with the fast-refresh disposer, like the other app services); it loads persisted shares, re-ingests native handoffs on every resume through the new subscribeAppActive helper, and alerts directly when an import fails. Screens read it with useSyncExternalStore through the same useIncomingShare hook. presentPendingIncomingShare runs when the inbox publishes and from the container's onReady/onStateChange, with the same presentation state machine and route params as before. <IncomingShareProvider> is gone. Effects: IncomingShareProvider.tsx 4 -> 0, Stack.tsx 1 -> 0, App.tsx 0 -> 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d145077 commit 6e3064f

4 files changed

Lines changed: 129 additions & 192 deletions

File tree

‎apps/mobile/src/App.tsx‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import { ThreadArrangementHost } from "./features/threads/ThreadArrangementSheet
2121
import * as Dialog from "./components/ui/Dialog";
2222
import { CloudAuthProvider } from "./features/cloud/CloudAuthProvider";
2323
import { prepareNativeShowcaseCapture } from "./features/showcase/nativeShowcaseScene";
24-
import { IncomingShareProvider } from "./features/sharing/IncomingShareProvider";
24+
import {
25+
presentPendingIncomingShare,
26+
startIncomingShareInbox,
27+
} from "./features/sharing/IncomingShareProvider";
2528
import {
2629
AppearancePreferencesProvider,
2730
useAppearancePreferences,
@@ -90,6 +93,7 @@ const Navigation = createStaticNavigation(RootStack);
9093
function handleNavigationStateChange(state: NavigationState | undefined): void {
9194
recordWorkspaceSelections(state);
9295
if (state) pruneNewTaskBranchCheckouts(state);
96+
presentPendingIncomingShare();
9397
}
9498

9599
function handleNavigationReady(): void {
@@ -102,6 +106,7 @@ const appServiceDisposers = [
102106
installPermissionUpdateNotice(),
103107
installThreadOutboxDelivery(),
104108
installComposerAttachmentUploads(),
109+
startIncomingShareInbox(),
105110
];
106111
disposeOnFoundationReplace(typeof module === "undefined" ? undefined : module.hot, () => {
107112
for (const dispose of appServiceDisposers) dispose();
@@ -156,15 +161,13 @@ function AppContent() {
156161
{/* native-stack needs the theme's dark flag to select dark native headers. */}
157162
<GlobalVoiceInputControl>
158163
<NativeLayoutMetricsProvider>
159-
<IncomingShareProvider>
160-
<Navigation
161-
ref={attachRootNavigation}
162-
linking={appLinking}
163-
onReady={handleNavigationReady}
164-
theme={navigationTheme}
165-
onStateChange={handleNavigationStateChange}
166-
/>
167-
</IncomingShareProvider>
164+
<Navigation
165+
ref={attachRootNavigation}
166+
linking={appLinking}
167+
onReady={handleNavigationReady}
168+
theme={navigationTheme}
169+
onStateChange={handleNavigationStateChange}
170+
/>
168171
<Dialog.Host />
169172
<ThreadArrangementHost />
170173
<ProjectChipIconRasterizer />

‎apps/mobile/src/Stack.tsx‎

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
createNativeStackScreen,
1616
type NativeStackNavigationOptions,
1717
} from "@react-navigation/native-stack";
18-
import { useEffect, useRef, type ReactNode } from "react";
18+
import type { ReactNode } from "react";
1919
import { Platform, Pressable, ScrollView, StyleSheet, useWindowDimensions } from "react-native";
2020
import { useResolveClassNames } from "uniwind";
2121

@@ -139,20 +139,12 @@ import {
139139
SettingsLegalDocumentExternalHeaderButton,
140140
} from "./features/settings/components/SettingsLegalDocumentRouteScreen";
141141
import { useAppShortcuts } from "./features/shortcuts/useAppShortcuts";
142-
import { useIncomingShare } from "./features/sharing/IncomingShareProvider";
143-
import {
144-
EMPTY_INCOMING_SHARE_PRESENTATION_STATE,
145-
transitionIncomingSharePresentation,
146-
} from "./features/sharing/incoming-share-presentation";
147142
import { NATIVE_LIQUID_GLASS_SUPPORTED } from "./native/native-glass";
148143
import { deriveLayout } from "./lib/layout";
149144
import { useNativeLayoutMetrics } from "./native/native-layout-metrics";
150145
import { nativeHeaderScrollEdgeEffects } from "./native/StackHeader";
151146
import { HORIZONTAL_FORM_SHEET_OPTIONS, formSheetDetents } from "./native/sheet-surface";
152-
import {
153-
selectWorkspaceDetail,
154-
workspaceDetailRouter,
155-
} from "./features/workspace/workspace-detail-selection";
147+
import { workspaceDetailRouter } from "./features/workspace/workspace-detail-selection";
156148

157149
const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
158150

@@ -498,9 +490,6 @@ function RootStackLayout(props: {
498490
readonly children: React.ReactNode;
499491
readonly state: NavigationState;
500492
}) {
501-
const navigation = useNavigation();
502-
const { pendingShare } = useIncomingShare();
503-
const sharePresentationRef = useRef(EMPTY_INCOMING_SHARE_PRESENTATION_STATE);
504493
const path = getPathFromState(props.state, navigationPathConfig);
505494
const pathname = path.startsWith("/") ? path : `/${path}`;
506495
const workspaceLocation = workspaceLocationFromState(props.state);
@@ -519,22 +508,6 @@ function RootStackLayout(props: {
519508
useAgentNotificationNavigation(workspaceLocation.pathname);
520509
useConnectOnboardingNavigation();
521510
useAppShortcuts(props.state);
522-
useEffect(() => {
523-
const transition = transitionIncomingSharePresentation(sharePresentationRef.current, {
524-
isShareSheetPresented: isDraftThreadRoute(props.state.routes[props.state.index]),
525-
pendingShareId: pendingShare?.id ?? null,
526-
});
527-
sharePresentationRef.current = transition.state;
528-
if (!transition.shareIdToPresent) {
529-
return;
530-
}
531-
navigation.dispatch(
532-
selectWorkspaceDetail({
533-
name: "Thread",
534-
params: { draft: { incomingShareId: transition.shareIdToPresent } },
535-
}),
536-
);
537-
}, [navigation, pendingShare, props.state]);
538511

539512
return (
540513
<NewTaskFlowProvider active={isDraftThreadRoute(draftRoute)} routeDraftId={routeDraftId}>

0 commit comments

Comments
 (0)