···3838 type MessagesTabNavigatorParams,
3939 type MyProfileTabNavigatorParams,
4040 type NotificationsTabNavigatorParams,
4141+ type RouteParams,
4142 type SearchTabNavigatorParams,
4343+ type State,
4244} from '#/lib/routes/types'
4343-import {type RouteParams, type State} from '#/lib/routes/types'
4445import {attachRouteToLogEvents, logEvent} from '#/lib/statsig/statsig'
4546import {bskyTitle} from '#/lib/strings/headings'
4647import {logger} from '#/logger'
···144145import {Referrer} from '../modules/expo-bluesky-swiss-army'
145146146147const navigationRef = createNavigationContainerRef<AllNavigatorParams>()
148148+149149+/**
150150+ * Stores the navigation state before account switch on native.
151151+ * This allows the user to stay on the same page when switching accounts.
152152+ */
153153+let storedNavigationStateForAccountSwitch: State | undefined
154154+155155+export function storeNavigationStateForAccountSwitch() {
156156+ if (IS_NATIVE && navigationRef.isReady()) {
157157+ storedNavigationStateForAccountSwitch = navigationRef.getRootState()
158158+ }
159159+}
160160+161161+function consumeStoredNavigationState(): State | undefined {
162162+ const state = storedNavigationStateForAccountSwitch
163163+ storedNavigationStateForAccountSwitch = undefined
164164+ return state
165165+}
147166148167const HomeTab = createNativeStackNavigatorWithAuth<HomeTabNavigatorParams>()
149168const SearchTab = createNativeStackNavigatorWithAuth<SearchTabNavigatorParams>()
···899918900919 const disableVerifyEmailReminder = useDisableVerifyEmailReminder()
901920921921+ // Consume stored navigation state from account switch (native only)
922922+ const initialState = IS_NATIVE ? consumeStoredNavigationState() : undefined
923923+902924 /**
903925 * Handle navigation to a conversation, or prepares for account switch.
904926 *
···10051027 ref={navigationRef}
10061028 linking={LINKING}
10071029 theme={theme}
10301030+ initialState={initialState}
10081031 onStateChange={() => {
10091032 logger.metric(
10101033 'router:navigate',
+3
src/lib/hooks/useAccountSwitcher.ts
···66import {type SessionAccount, useSessionApi} from '#/state/session'
77import {useLoggedOutViewControls} from '#/state/shell/logged-out'
88import * as Toast from '#/view/com/util/Toast'
99+import {storeNavigationStateForAccountSwitch} from '#/Navigation'
910import {logEvent} from '../statsig/statsig'
1011import {type LogEvents} from '../statsig/statsig'
1112···2728 try {
2829 setPendingDid(account.did)
2930 if (account.accessJwt) {
3131+ // Store navigation state before switching so user stays on the same page
3232+ storeNavigationStateForAccountSwitch()
3033 await resumeSession(account, true)
3134 logEvent('account:loggedIn', {logContext, withPassword: false})
3235 Toast.show(_(msg`Signed in as @${account.handle}`))