diff --git a/src/components/WorkspaceSwitcherButton.tsx b/src/components/WorkspaceSwitcherButton.tsx index 04349526aaeab..cc875c25d14eb 100644 --- a/src/components/WorkspaceSwitcherButton.tsx +++ b/src/components/WorkspaceSwitcherButton.tsx @@ -18,14 +18,9 @@ type WorkspaceSwitcherButtonOnyxProps = { policy: OnyxEntry; }; -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 @@ function WorkspaceSwitcherButton({policy, onSwitchWorkspace}: WorkspaceSwitcherB source: avatar, name: policy?.name ?? '', type: CONST.ICON_TYPE_WORKSPACE, - id: policy?.id ?? '-1', + id: policy?.id ?? CONST.DEFAULT_NUMBER_ID, }; }, [policy]); @@ -54,7 +49,6 @@ function WorkspaceSwitcherButton({policy, onSwitchWorkspace}: WorkspaceSwitcherB accessible testID="WorkspaceSwitcherButton" onPress={() => { - onSwitchWorkspace?.(); pressableRef?.current?.blur(); interceptAnonymousUser(() => { Navigation.navigate(ROUTES.WORKSPACE_SWITCHER); diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index e01d0fe3115f2..e3f34ea3bea35 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -25,6 +25,7 @@ import Log from '@libs/Log'; 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 @@ Onyx.connect({ return; } - currentAccountID = value.accountID ?? -1; + currentAccountID = value.accountID ?? CONST.DEFAULT_NUMBER_ID; 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 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie } const initialReport = ReportUtils.findLastAccessedReport(!canUseDefaultRooms, shouldOpenOnAdminRoom(), activeWorkspaceID); - return initialReport?.reportID ?? ''; + return initialReport?.reportID; }); useEffect(() => { @@ -464,7 +465,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie options={{ headerShown: false, presentation: Presentation.TRANSPARENT_MODAL, - animation: 'none', + animation: Animations.NONE, }} getComponent={loadProfileAvatar} listeners={modalScreenListeners} diff --git a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx index 01caa79692f12..c72c4de01e4e5 100644 --- a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx @@ -22,15 +22,9 @@ type TopBarProps = { activeWorkspaceID?: string; shouldDisplaySearch?: boolean; shouldDisplayCancelSearch?: boolean; - - /** - * Callback used to keep track of the workspace switching process in the BaseSidebarScreen. - * Passed to the WorkspaceSwitcherButton component. - */ - onSwitchWorkspace?: () => void; }; -function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true, shouldDisplayCancelSearch = false, onSwitchWorkspace}: TopBarProps) { +function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true, shouldDisplayCancelSearch = false}: TopBarProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const policy = usePolicy(activeWorkspaceID); @@ -53,10 +47,7 @@ function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true, dataSet={{dragArea: true}} > - + PolicyUtils.shouldShowPolicy(policy, !!isOffline, currentUserLogin) && !policy?.isJoinRequestPending) .map((policy) => ({ text: policy?.name ?? '', - policyID: policy?.id ?? '-1', + policyID: policy?.id, brickRoadIndicator: getIndicatorTypeForPolicy(policy?.id), icons: [ { diff --git a/src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.native.tsx b/src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.native.tsx new file mode 100644 index 0000000000000..a3df127564b1b --- /dev/null +++ b/src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.native.tsx @@ -0,0 +1,10 @@ +import {InteractionManager} from 'react-native'; +import Navigation from '@libs/Navigation/Navigation'; + +function switchPolicyAfterInteractions(newPolicyID: string | undefined) { + InteractionManager.runAfterInteractions(() => { + Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); + }); +} + +export default switchPolicyAfterInteractions; diff --git a/src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.tsx b/src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.tsx new file mode 100644 index 0000000000000..612759a8601c9 --- /dev/null +++ b/src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.tsx @@ -0,0 +1,7 @@ +import Navigation from '@libs/Navigation/Navigation'; + +function switchPolicyAfterInteractions(newPolicyID: string | undefined) { + Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); +} + +export default switchPolicyAfterInteractions; diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx index 814daa82ea3d3..a1e4f0e4a22ad 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx @@ -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 @@ function BaseSidebarScreen() { const activeWorkspaceID = useActiveWorkspaceFromNavigationState(); const {translate} = useLocalize(); const {shouldUseNarrowLayout} = useResponsiveLayout(); - const [activeWorkspace] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`); + const [activeWorkspace] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? CONST.DEFAULT_NUMBER_ID}`); 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 @@ function BaseSidebarScreen() { breadcrumbLabel={translate('common.inbox')} activeWorkspaceID={activeWorkspaceID} shouldDisplaySearch={shouldDisplaySearch} - onSwitchWorkspace={() => (isSwitchingWorkspace.current = true)} />