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