-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42684 from abzokhattab/fix-chat-navigation
Fix chat navigation
- Loading branch information
Showing
6 changed files
with
177 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, {useCallback, useMemo, useState} from 'react'; | ||
import ActiveWorkspaceContext from '@components/ActiveWorkspace/ActiveWorkspaceContext'; | ||
import CONST from '@src/CONST'; | ||
import type ChildrenProps from '@src/types/utils/ChildrenProps'; | ||
|
||
function ActiveWorkspaceContextProvider({children}: ChildrenProps) { | ||
const [activeWorkspaceID, updateActiveWorkspaceID] = useState<string | undefined>(undefined); | ||
|
||
const setActiveWorkspaceID = useCallback((workspaceID: string | undefined) => { | ||
updateActiveWorkspaceID(workspaceID); | ||
if (workspaceID && sessionStorage) { | ||
sessionStorage?.setItem(CONST.SESSION_STORAGE_KEYS.ACTIVE_WORKSPACE_ID, workspaceID); | ||
} else { | ||
sessionStorage?.removeItem(CONST.SESSION_STORAGE_KEYS.ACTIVE_WORKSPACE_ID); | ||
} | ||
}, []); | ||
|
||
const value = useMemo( | ||
() => ({ | ||
activeWorkspaceID, | ||
setActiveWorkspaceID, | ||
}), | ||
[activeWorkspaceID, setActiveWorkspaceID], | ||
); | ||
|
||
return <ActiveWorkspaceContext.Provider value={value}>{children}</ActiveWorkspaceContext.Provider>; | ||
} | ||
|
||
export default ActiveWorkspaceContextProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...ibs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar/index.website.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import {useNavigation, useNavigationState} from '@react-navigation/native'; | ||
import React, {useCallback, useEffect} from 'react'; | ||
import {View} from 'react-native'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import Icon from '@components/Icon'; | ||
import * as Expensicons from '@components/Icon/Expensicons'; | ||
import {PressableWithFeedback} from '@components/Pressable'; | ||
import Tooltip from '@components/Tooltip'; | ||
import useActiveWorkspace from '@hooks/useActiveWorkspace'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useTheme from '@hooks/useTheme'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as Session from '@libs/actions/Session'; | ||
import interceptAnonymousUser from '@libs/interceptAnonymousUser'; | ||
import getTopmostBottomTabRoute from '@libs/Navigation/getTopmostBottomTabRoute'; | ||
import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import type {RootStackParamList, State} from '@libs/Navigation/types'; | ||
import {getChatTabBrickRoad} from '@libs/WorkspacesSettingsUtils'; | ||
import BottomTabAvatar from '@pages/home/sidebar/BottomTabAvatar'; | ||
import BottomTabBarFloatingActionButton from '@pages/home/sidebar/BottomTabBarFloatingActionButton'; | ||
import variables from '@styles/variables'; | ||
import * as Welcome from '@userActions/Welcome'; | ||
import CONST from '@src/CONST'; | ||
import NAVIGATORS from '@src/NAVIGATORS'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {Route} from '@src/ROUTES'; | ||
import ROUTES from '@src/ROUTES'; | ||
import SCREENS from '@src/SCREENS'; | ||
|
||
type PurposeForUsingExpensifyModalOnyxProps = { | ||
isLoadingApp: OnyxEntry<boolean>; | ||
}; | ||
type PurposeForUsingExpensifyModalProps = PurposeForUsingExpensifyModalOnyxProps; | ||
|
||
function BottomTabBar({isLoadingApp = false}: PurposeForUsingExpensifyModalProps) { | ||
const theme = useTheme(); | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
const navigation = useNavigation(); | ||
const {activeWorkspaceID: contextActiveWorkspaceID} = useActiveWorkspace(); | ||
const activeWorkspaceID = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.ACTIVE_WORKSPACE_ID) ?? contextActiveWorkspaceID; | ||
|
||
useEffect(() => { | ||
const navigationState = navigation.getState() as State<RootStackParamList> | undefined; | ||
const routes = navigationState?.routes; | ||
const currentRoute = routes?.[navigationState?.index ?? 0]; | ||
// When we are redirected to the Settings tab from the OldDot, we don't want to call the Welcome.show() method. | ||
// To prevent this, the value of the bottomTabRoute?.name is checked here | ||
if (!!(currentRoute && currentRoute.name !== NAVIGATORS.BOTTOM_TAB_NAVIGATOR && currentRoute.name !== NAVIGATORS.CENTRAL_PANE_NAVIGATOR) || Session.isAnonymousUser()) { | ||
return; | ||
} | ||
|
||
Welcome.isOnboardingFlowCompleted({onNotCompleted: () => Navigation.navigate(ROUTES.ONBOARDING_ROOT)}); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [isLoadingApp]); | ||
|
||
// Parent navigator of the bottom tab bar is the root navigator. | ||
const currentTabName = useNavigationState<RootStackParamList, string | undefined>((state) => { | ||
const topmostCentralPaneRoute = getTopmostCentralPaneRoute(state); | ||
|
||
if (topmostCentralPaneRoute && topmostCentralPaneRoute.name === SCREENS.SEARCH.CENTRAL_PANE) { | ||
return SCREENS.SEARCH.CENTRAL_PANE; | ||
} | ||
|
||
const topmostBottomTabRoute = getTopmostBottomTabRoute(state); | ||
return topmostBottomTabRoute?.name ?? SCREENS.HOME; | ||
}); | ||
|
||
const chatTabBrickRoad = getChatTabBrickRoad(activeWorkspaceID); | ||
|
||
const navigateToChats = useCallback(() => { | ||
const route = activeWorkspaceID ? (`/w/${activeWorkspaceID}/home` as Route) : ROUTES.HOME; | ||
Navigation.navigate(route); | ||
}, [activeWorkspaceID]); | ||
|
||
return ( | ||
<View style={styles.bottomTabBarContainer}> | ||
<Tooltip text={translate('common.inbox')}> | ||
<PressableWithFeedback | ||
onPress={navigateToChats} | ||
role={CONST.ROLE.BUTTON} | ||
accessibilityLabel={translate('common.inbox')} | ||
wrapperStyle={styles.flex1} | ||
style={styles.bottomTabBarItem} | ||
> | ||
<View> | ||
<Icon | ||
src={Expensicons.Inbox} | ||
fill={currentTabName === SCREENS.HOME ? theme.iconMenu : theme.icon} | ||
width={variables.iconBottomBar} | ||
height={variables.iconBottomBar} | ||
/> | ||
{chatTabBrickRoad && ( | ||
<View style={styles.bottomTabStatusIndicator(chatTabBrickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.INFO ? theme.iconSuccessFill : theme.danger)} /> | ||
)} | ||
</View> | ||
</PressableWithFeedback> | ||
</Tooltip> | ||
<Tooltip text={translate('common.search')}> | ||
<PressableWithFeedback | ||
onPress={() => { | ||
interceptAnonymousUser(() => Navigation.navigate(ROUTES.SEARCH.getRoute(CONST.TAB_SEARCH.ALL))); | ||
}} | ||
role={CONST.ROLE.BUTTON} | ||
accessibilityLabel={translate('common.search')} | ||
wrapperStyle={styles.flex1} | ||
style={styles.bottomTabBarItem} | ||
> | ||
<View> | ||
<Icon | ||
src={Expensicons.MoneySearch} | ||
fill={currentTabName === SCREENS.SEARCH.BOTTOM_TAB || currentTabName === SCREENS.SEARCH.CENTRAL_PANE ? theme.iconMenu : theme.icon} | ||
width={variables.iconBottomBar} | ||
height={variables.iconBottomBar} | ||
/> | ||
</View> | ||
</PressableWithFeedback> | ||
</Tooltip> | ||
<BottomTabAvatar isSelected={currentTabName === SCREENS.SETTINGS.ROOT} /> | ||
<View style={[styles.flex1, styles.bottomTabBarItem]}> | ||
<BottomTabBarFloatingActionButton /> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
BottomTabBar.displayName = 'BottomTabBar'; | ||
|
||
export default withOnyx<PurposeForUsingExpensifyModalProps, PurposeForUsingExpensifyModalOnyxProps>({ | ||
isLoadingApp: { | ||
key: ONYXKEYS.IS_LOADING_APP, | ||
}, | ||
})(BottomTabBar); |