-
Notifications
You must be signed in to change notification settings - Fork 3k
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 chat navigation #42684
Merged
Merged
Fix chat navigation #42684
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ce10020
Fixing the chat icon navigation
abzokhattab 809dcda
Merge remote-tracking branch 'origin/main' into fix-chat-navigation
abzokhattab 1a6199d
Use session storage to save the current active workspace
abzokhattab c83f7ce
Merge remote-tracking branch 'origin/main' into fix-chat-navigation
abzokhattab 0d68d3d
fix sessionStorage not found for mobile
abzokhattab 6b063e8
Fix sessionStorage not found error for native devices
abzokhattab 9b431fa
navigate to home in native devices
abzokhattab 7f647fb
refactoring
abzokhattab ac03bdb
Merge remote-tracking branch 'origin/main' into fix-chat-navigation
abzokhattab 4e64093
Merge remote-tracking branch 'origin/main' into fix-chat-navigation
abzokhattab d948537
merging into main
abzokhattab 40d9c24
minor change
abzokhattab 57d77e3
eslint fix
abzokhattab f6deb18
Merge remote-tracking branch 'origin/main' into fix-chat-navigation
abzokhattab 191f197
merge to main
abzokhattab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Might be related, when user is already in home and presses the home tab page blinks #43585