-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: WS switcher blank screen, keep workspace history #54030
Changes from 14 commits
6b4078c
a64553e
99f817d
30f55fe
abed839
3aa698d
6e3b566
9665162
4ddab5d
70a19d6
05a5512
0eda66d
6c7218f
8f7ef9f
55b7ab4
805d4bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,14 +18,9 @@ | |
policy: OnyxEntry<Policy>; | ||
}; | ||
|
||
type WorkspaceSwitcherButtonProps = WorkspaceSwitcherButtonOnyxProps & { | ||
/** | ||
* Callback used to keep track of the workspace switching process in the BaseSidebarScreen. | ||
*/ | ||
onSwitchWorkspace?: () => void; | ||
}; | ||
type WorkspaceSwitcherButtonProps = WorkspaceSwitcherButtonOnyxProps; | ||
|
||
function WorkspaceSwitcherButton({policy, onSwitchWorkspace}: WorkspaceSwitcherButtonProps) { | ||
function WorkspaceSwitcherButton({policy}: WorkspaceSwitcherButtonProps) { | ||
const {translate} = useLocalize(); | ||
const theme = useTheme(); | ||
|
||
|
@@ -41,7 +36,7 @@ | |
source: avatar, | ||
name: policy?.name ?? '', | ||
type: CONST.ICON_TYPE_WORKSPACE, | ||
id: policy?.id ?? '-1', | ||
Check failure on line 39 in src/components/WorkspaceSwitcherButton.tsx
|
||
}; | ||
}, [policy]); | ||
|
||
|
@@ -54,7 +49,6 @@ | |
accessible | ||
testID="WorkspaceSwitcherButton" | ||
onPress={() => { | ||
onSwitchWorkspace?.(); | ||
pressableRef?.current?.blur(); | ||
interceptAnonymousUser(() => { | ||
Navigation.navigate(ROUTES.WORKSPACE_SWITCHER); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import NavBarManager from '@libs/NavBarManager'; | ||
import getCurrentUrl from '@libs/Navigation/currentUrl'; | ||
import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; | ||
import Animations from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation'; | ||
import Presentation from '@libs/Navigation/PlatformStackNavigation/navigationOptions/presentation'; | ||
import type {PlatformStackNavigationOptions} from '@libs/Navigation/PlatformStackNavigation/types'; | ||
import shouldOpenOnAdminRoom from '@libs/Navigation/shouldOpenOnAdminRoom'; | ||
|
@@ -147,7 +148,7 @@ | |
return; | ||
} | ||
|
||
currentAccountID = value.accountID ?? -1; | ||
Check failure on line 151 in src/libs/Navigation/AppNavigator/AuthScreens.tsx
|
||
|
||
if (Navigation.isActiveRoute(ROUTES.SIGN_IN_MODAL)) { | ||
// This means sign in in RHP was successful, so we can subscribe to user events | ||
|
@@ -249,7 +250,7 @@ | |
} | ||
|
||
const initialReport = ReportUtils.findLastAccessedReport(!canUseDefaultRooms, shouldOpenOnAdminRoom(), activeWorkspaceID); | ||
return initialReport?.reportID ?? ''; | ||
Check failure on line 253 in src/libs/Navigation/AppNavigator/AuthScreens.tsx
|
||
}); | ||
|
||
useEffect(() => { | ||
|
@@ -464,7 +465,7 @@ | |
options={{ | ||
headerShown: false, | ||
presentation: Presentation.TRANSPARENT_MODAL, | ||
animation: 'none', | ||
animation: Animations.NONE, | ||
}} | ||
getComponent={loadProfileAvatar} | ||
listeners={modalScreenListeners} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import type {NativeStackNavigationOptions} from '@react-navigation/native-stack'; | ||
import Animations from '..'; | ||
import {InternalPlatformAnimations} from '..'; | ||
import type NoneTransitionNavigationOptions from './types'; | ||
|
||
const none: NoneTransitionNavigationOptions = {animation: Animations.NONE, gestureEnabled: false} satisfies NativeStackNavigationOptions; | ||
const none: NoneTransitionNavigationOptions = { | ||
animation: InternalPlatformAnimations.NONE, | ||
gestureEnabled: false, | ||
} satisfies NativeStackNavigationOptions; | ||
|
||
export default none; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
import switchPolicyAfterInteractions from './switchPolicyAfterInteractions'; | ||
import WorkspaceCardCreateAWorkspace from './WorkspaceCardCreateAWorkspace'; | ||
|
||
type WorkspaceListItem = { | ||
|
@@ -87,7 +88,9 @@ | |
setActiveWorkspaceID(newPolicyID); | ||
Navigation.goBack(); | ||
if (newPolicyID !== activeWorkspaceID) { | ||
Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); | ||
// On native platforms, we will see a blank screen if we navigate to a new HomeScreen route while navigating back at the same time. | ||
// Therefore we delay switching the workspace until after back navigation, using the InteractionManager. | ||
switchPolicyAfterInteractions(newPolicyID); | ||
} | ||
}, | ||
[activeWorkspaceID, setActiveWorkspaceID, isFocused], | ||
|
@@ -102,7 +105,7 @@ | |
.filter((policy) => PolicyUtils.shouldShowPolicy(policy, !!isOffline, currentUserLogin) && !policy?.isJoinRequestPending) | ||
.map((policy) => ({ | ||
text: policy?.name ?? '', | ||
policyID: policy?.id ?? '-1', | ||
Check failure on line 108 in src/pages/WorkspaceSwitcherPage/index.tsx
|
||
brickRoadIndicator: getIndicatorTypeForPolicy(policy?.id), | ||
icons: [ | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {InteractionManager} from 'react-native'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
|
||
function switchPolicyAfterInteractions(newPolicyID: string | undefined) { | ||
InteractionManager.runAfterInteractions(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using Details in this proposal: #54554 (comment) PR: #55443 |
||
Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); | ||
}); | ||
} | ||
|
||
export default switchPolicyAfterInteractions; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
|
||
function switchPolicyAfterInteractions(newPolicyID: string | undefined) { | ||
Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); | ||
} | ||
|
||
export default switchPolicyAfterInteractions; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React, {useEffect, useRef} from 'react'; | ||
import React, {useEffect} from 'react'; | ||
import {View} from 'react-native'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
|
@@ -21,32 +21,18 @@ | |
const activeWorkspaceID = useActiveWorkspaceFromNavigationState(); | ||
const {translate} = useLocalize(); | ||
const {shouldUseNarrowLayout} = useResponsiveLayout(); | ||
const [activeWorkspace] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`); | ||
Check failure on line 24 in src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx
|
||
|
||
useEffect(() => { | ||
Performance.markStart(CONST.TIMING.SIDEBAR_LOADED); | ||
Timing.start(CONST.TIMING.SIDEBAR_LOADED); | ||
}, []); | ||
|
||
const isSwitchingWorkspace = useRef(false); | ||
useEffect(() => { | ||
// Whether the active workspace or the "Everything" page is loaded | ||
const isWorkspaceOrEverythingLoaded = !!activeWorkspace || activeWorkspaceID === undefined; | ||
|
||
// If we are currently switching workspaces, we don't want to do anything until the target workspace is loaded | ||
if (isSwitchingWorkspace.current) { | ||
if (isWorkspaceOrEverythingLoaded) { | ||
isSwitchingWorkspace.current = false; | ||
} | ||
return; | ||
} | ||
|
||
// Otherwise, if the workspace is already loaded, we don't need to do anything | ||
if (isWorkspaceOrEverythingLoaded) { | ||
if (!!activeWorkspace || activeWorkspaceID === undefined) { | ||
return; | ||
} | ||
|
||
isSwitchingWorkspace.current = true; | ||
Navigation.navigateWithSwitchPolicyID({policyID: undefined}); | ||
updateLastAccessedWorkspace(undefined); | ||
}, [activeWorkspace, activeWorkspaceID]); | ||
|
@@ -67,7 +53,6 @@ | |
breadcrumbLabel={translate('common.inbox')} | ||
activeWorkspaceID={activeWorkspaceID} | ||
shouldDisplaySearch={shouldDisplaySearch} | ||
onSwitchWorkspace={() => (isSwitchingWorkspace.current = true)} | ||
/> | ||
<View style={[styles.flex1]}> | ||
<SidebarLinksData insets={insets} /> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simply removing this caused #54509