@@ -9,10 +9,10 @@ import { GestureHandlerRootView } from "react-native-gesture-handler";
99import { KeyboardProvider } from "react-native-keyboard-controller" ;
1010import { SafeAreaProvider } from "react-native-safe-area-context" ;
1111import {
12- createNavigationContainerRef ,
1312 createStaticNavigation ,
1413 getActionFromState ,
1514 getStateFromPath ,
15+ type NavigationState ,
1616} from "@react-navigation/native" ;
1717
1818import { RegistryContext } from "@effect/atom-react" ;
@@ -40,8 +40,9 @@ import {
4040 type FoundationHotModule ,
4141} from "./lib/foundation-fast-refresh" ;
4242import { useMobileNavigationTheme } from "./lib/useMobileNavigationTheme" ;
43- import { useUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarningGc" ;
43+ import { installUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarningGc" ;
4444import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator" ;
45+ import { installSubscriptionUsageRefresh } from "./widgets/useSubscriptionUsage" ;
4546import { GlobalVoiceInputControl } from "./features/voice-input/GlobalVoiceInputControl" ;
4647import { restoreSettingsLinkState } from "./features/settings/settings-navigation" ;
4748import {
@@ -52,6 +53,8 @@ import {
5253} from "./features/workspace/workspace-selection-store" ;
5354import { workspaceDetailLinkAction } from "./features/workspace/workspace-detail-selection" ;
5455import { NativeLayoutMetricsProvider } from "./native/native-layout-metrics" ;
56+ import { attachRootNavigation , rootNavigationRef } from "./lib/rootNavigation" ;
57+ import { pruneNewTaskBranchCheckouts } from "./features/threads/NewTaskDraftRouteScreen" ;
5558
5659import "../global.css" ;
5760
@@ -84,11 +87,27 @@ const appLinking = {
8487} ;
8588
8689const Navigation = createStaticNavigation ( RootStack ) ;
87- const navigationRef = createNavigationContainerRef ( ) ;
90+
91+ function handleNavigationStateChange ( state : NavigationState | undefined ) : void {
92+ recordWorkspaceSelections ( state ) ;
93+ if ( state ) pruneNewTaskBranchCheckouts ( state ) ;
94+ }
95+
96+ function handleNavigationReady ( ) : void {
97+ handleNavigationStateChange ( rootNavigationRef . getRootState ( ) ) ;
98+ }
8899
89100declare const module : { readonly hot ?: FoundationHotModule } | undefined ;
90101
91102const appServiceDisposers = [
103+ installUiRuntimeMemoryWarningGc ( ) ,
104+ subscribeComposerDraftModelReconciliation ( {
105+ registry : appAtomRegistry ,
106+ threadShellAtom : environmentThreadShells . threadShellAtom ,
107+ threadRefsAtom : environmentThreadShells . threadRefsAtom ,
108+ shellStateAtom : environmentShell . stateAtom ,
109+ } ) ,
110+ installSubscriptionUsageRefresh ( ) ,
92111 installPermissionUpdateNotice ( ) ,
93112 installThreadOutboxDelivery ( ) ,
94113 installComposerAttachmentUploads ( ) ,
@@ -108,18 +127,6 @@ function SplashScreenCoordinator() {
108127}
109128
110129export default function App ( ) {
111- useUiRuntimeMemoryWarningGc ( ) ;
112- useEffect (
113- ( ) =>
114- subscribeComposerDraftModelReconciliation ( {
115- registry : appAtomRegistry ,
116- threadShellAtom : environmentThreadShells . threadShellAtom ,
117- threadRefsAtom : environmentThreadShells . threadRefsAtom ,
118- shellStateAtom : environmentShell . stateAtom ,
119- } ) ,
120- [ ] ,
121- ) ;
122-
123130 return (
124131 < RegistryContext . Provider value = { appAtomRegistry } >
125132 < CloudAuthProvider >
@@ -148,11 +155,11 @@ function AppContent() {
148155 < NativeLayoutMetricsProvider >
149156 < IncomingShareProvider >
150157 < Navigation
151- ref = { navigationRef }
158+ ref = { attachRootNavigation }
152159 linking = { appLinking }
153- onReady = { ( ) => recordWorkspaceSelections ( navigationRef . getRootState ( ) ) }
160+ onReady = { handleNavigationReady }
154161 theme = { navigationTheme }
155- onStateChange = { recordWorkspaceSelections }
162+ onStateChange = { handleNavigationStateChange }
156163 />
157164 </ IncomingShareProvider >
158165 < Dialog . Host />
0 commit comments