Skip to content

Commit

Permalink
revert: ws switcher home route setParams changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispader committed Dec 12, 2024
1 parent 50c1db8 commit 6b4078c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -53,10 +47,7 @@ function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true,
dataSet={{dragArea: true}}
>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter, styles.ml2]}>
<WorkspaceSwitcherButton
policy={policy}
onSwitchWorkspace={onSwitchWorkspace}
/>
<WorkspaceSwitcherButton policy={policy} />

<View style={[styles.ml3, styles.flex1]}>
<Breadcrumbs
Expand Down
13 changes: 1 addition & 12 deletions src/libs/Navigation/switchPolicyID.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CommonActions, getActionFromState} from '@react-navigation/core';
import {getActionFromState} from '@react-navigation/core';
import type {NavigationAction, NavigationContainerRef, NavigationState, PartialState} from '@react-navigation/native';
import {getPathFromState} from '@react-navigation/native';
import type {Writable} from 'type-fest';
Expand Down Expand Up @@ -52,17 +52,6 @@ function getActionForBottomTabNavigator(action: StackNavigationAction, state: Na
params.policyID = policyID;
}

// If the last route in the BottomTabNavigator is already a 'Home' route, we want to change the params rather than pushing a new 'Home' route,
// so that the screen does not get re-mounted. This would cause an empty screen/white flash when navigating back from the workspace switcher.
const homeRoute = bottomTabNavigatorRoute.state.routes.at(-1);
if (homeRoute && homeRoute.name === SCREENS.HOME) {
return {
...CommonActions.setParams(params),
source: homeRoute?.key,
};
}

// If there is no 'Home' route in the BottomTabNavigator or if we are updating a different navigator, we want to push a new route.
return {
type: CONST.NAVIGATION.ACTION_TYPE.PUSH,
payload: {
Expand Down
5 changes: 4 additions & 1 deletion src/pages/WorkspaceSwitcherPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {useIsFocused} from '@react-navigation/native';
import React, {useCallback, useMemo} from 'react';
import {InteractionManager} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import * as Expensicons from '@components/Icon/Expensicons';
Expand Down Expand Up @@ -85,10 +86,12 @@ function WorkspaceSwitcherPage() {
const newPolicyID = policyID === activeWorkspaceID ? undefined : policyID;

setActiveWorkspaceID(newPolicyID);
Navigation.goBack();
if (newPolicyID !== activeWorkspaceID) {
Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID});
}
InteractionManager.runAfterInteractions(() => {
Navigation.goBack();
});
},
[activeWorkspaceID, setActiveWorkspaceID, isFocused],
);
Expand Down
19 changes: 2 additions & 17 deletions src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx
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';
Expand Down Expand Up @@ -28,25 +28,11 @@ function BaseSidebarScreen() {
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]);
Expand All @@ -67,7 +53,6 @@ function BaseSidebarScreen() {
breadcrumbLabel={translate('common.inbox')}
activeWorkspaceID={activeWorkspaceID}
shouldDisplaySearch={shouldDisplaySearch}
onSwitchWorkspace={() => (isSwitchingWorkspace.current = true)}
/>
<View style={[styles.flex1]}>
<SidebarLinksData insets={insets} />
Expand Down

0 comments on commit 6b4078c

Please sign in to comment.