Bluesky app fork with some witchin' additions 💫

feat(mobile): stay on the same page when switching accounts

xan.lol cb54cd87 50bb9174

verified
+27 -1
+24 -1
src/Navigation.tsx
··· 38 38 type MessagesTabNavigatorParams, 39 39 type MyProfileTabNavigatorParams, 40 40 type NotificationsTabNavigatorParams, 41 + type RouteParams, 41 42 type SearchTabNavigatorParams, 43 + type State, 42 44 } from '#/lib/routes/types' 43 - import {type RouteParams, type State} from '#/lib/routes/types' 44 45 import {attachRouteToLogEvents, logEvent} from '#/lib/statsig/statsig' 45 46 import {bskyTitle} from '#/lib/strings/headings' 46 47 import {logger} from '#/logger' ··· 144 145 import {Referrer} from '../modules/expo-bluesky-swiss-army' 145 146 146 147 const navigationRef = createNavigationContainerRef<AllNavigatorParams>() 148 + 149 + /** 150 + * Stores the navigation state before account switch on native. 151 + * This allows the user to stay on the same page when switching accounts. 152 + */ 153 + let storedNavigationStateForAccountSwitch: State | undefined 154 + 155 + export function storeNavigationStateForAccountSwitch() { 156 + if (IS_NATIVE && navigationRef.isReady()) { 157 + storedNavigationStateForAccountSwitch = navigationRef.getRootState() 158 + } 159 + } 160 + 161 + function consumeStoredNavigationState(): State | undefined { 162 + const state = storedNavigationStateForAccountSwitch 163 + storedNavigationStateForAccountSwitch = undefined 164 + return state 165 + } 147 166 148 167 const HomeTab = createNativeStackNavigatorWithAuth<HomeTabNavigatorParams>() 149 168 const SearchTab = createNativeStackNavigatorWithAuth<SearchTabNavigatorParams>() ··· 899 918 900 919 const disableVerifyEmailReminder = useDisableVerifyEmailReminder() 901 920 921 + // Consume stored navigation state from account switch (native only) 922 + const initialState = IS_NATIVE ? consumeStoredNavigationState() : undefined 923 + 902 924 /** 903 925 * Handle navigation to a conversation, or prepares for account switch. 904 926 * ··· 1005 1027 ref={navigationRef} 1006 1028 linking={LINKING} 1007 1029 theme={theme} 1030 + initialState={initialState} 1008 1031 onStateChange={() => { 1009 1032 logger.metric( 1010 1033 'router:navigate',
+3
src/lib/hooks/useAccountSwitcher.ts
··· 6 6 import {type SessionAccount, useSessionApi} from '#/state/session' 7 7 import {useLoggedOutViewControls} from '#/state/shell/logged-out' 8 8 import * as Toast from '#/view/com/util/Toast' 9 + import {storeNavigationStateForAccountSwitch} from '#/Navigation' 9 10 import {logEvent} from '../statsig/statsig' 10 11 import {type LogEvents} from '../statsig/statsig' 11 12 ··· 27 28 try { 28 29 setPendingDid(account.did) 29 30 if (account.accessJwt) { 31 + // Store navigation state before switching so user stays on the same page 32 + storeNavigationStateForAccountSwitch() 30 33 await resumeSession(account, true) 31 34 logEvent('account:loggedIn', {logContext, withPassword: false}) 32 35 Toast.show(_(msg`Signed in as @${account.handle}`))