forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
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 Expensify#28277 from adamgrzybowski/@swm/global-na…
…v-menu-v1 @swm/global nav menu v1
- Loading branch information
Showing
30 changed files
with
408 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import CONST from './CONST'; | ||
import SCREENS from './SCREENS'; | ||
|
||
export default { | ||
[CONST.GLOBAL_NAVIGATION_OPTION.HOME]: [SCREENS.HOME_OLDDOT], | ||
[CONST.GLOBAL_NAVIGATION_OPTION.CHATS]: [SCREENS.REPORT], | ||
[CONST.GLOBAL_NAVIGATION_OPTION.SPEND]: [SCREENS.EXPENSES_OLDDOT, SCREENS.REPORTS_OLDDOT, SCREENS.INSIGHTS_OLDDOT], | ||
[CONST.GLOBAL_NAVIGATION_OPTION.WORKSPACES]: [SCREENS.INDIVIDUAL_WORKSPACES_OLDDOT, SCREENS.GROUPS_WORKSPACES_OLDDOT, SCREENS.CARDS_AND_DOMAINS_OLDDOT], | ||
} as const; |
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
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
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,32 @@ | ||
import lodashFindLast from 'lodash/findLast'; | ||
|
||
/** | ||
* Find the name of top most central pane route. | ||
* | ||
* @param {Object} state - The react-navigation state | ||
* @returns {String | undefined} - It's possible that there is no central pane in the state. | ||
*/ | ||
function getTopMostCentralPaneRouteName(state) { | ||
if (!state) { | ||
return undefined; | ||
} | ||
const topmostCentralPane = lodashFindLast(state.routes, (route) => route.name === 'CentralPaneNavigator'); | ||
|
||
if (!topmostCentralPane) { | ||
return undefined; | ||
} | ||
|
||
if (topmostCentralPane.state && topmostCentralPane.state.routes) { | ||
// State may don't have index in some cases. But in this case there will be only one route in state. | ||
return topmostCentralPane.state.routes[topmostCentralPane.state.index || 0].name; | ||
} | ||
|
||
if (topmostCentralPane.params) { | ||
// State may don't have inner state in some cases (e.g generating actions from path). But in this case there will be params available. | ||
return topmostCentralPane.params.screen; | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
export default getTopMostCentralPaneRouteName; |
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
64 changes: 64 additions & 0 deletions
64
src/pages/home/sidebar/GlobalNavigation/GlobalNavigationMenuItem.js
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,64 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import Text from '../../../../components/Text'; | ||
import styles from '../../../../styles/styles'; | ||
import * as StyleUtils from '../../../../styles/StyleUtils'; | ||
import Icon from '../../../../components/Icon'; | ||
import CONST from '../../../../CONST'; | ||
import variables from '../../../../styles/variables'; | ||
import PressableWithFeedback from '../../../../components/Pressable/PressableWithFeedback'; | ||
|
||
const propTypes = { | ||
/** Icon to display */ | ||
icon: PropTypes.elementType, | ||
|
||
/** Text to display for the item */ | ||
title: PropTypes.string, | ||
|
||
/** Function to fire when component is pressed */ | ||
onPress: PropTypes.func, | ||
|
||
/** Whether item is focused or active */ | ||
isFocused: PropTypes.bool, | ||
}; | ||
|
||
const defaultProps = { | ||
icon: undefined, | ||
isFocused: false, | ||
onPress: () => {}, | ||
title: '', | ||
}; | ||
|
||
const GlobalNavigationMenuItem = React.forwardRef(({icon, title, isFocused, onPress}, ref) => ( | ||
<PressableWithFeedback | ||
onPress={() => !isFocused && onPress()} | ||
style={styles.globalNavigationItemContainer} | ||
ref={ref} | ||
accessibilityRole={CONST.ACCESSIBILITY_ROLE.MENUITEM} | ||
accessibilityLabel={title} | ||
> | ||
{({pressed}) => ( | ||
<View style={[styles.alignItemsCenter, styles.flexRow, styles.flex1]}> | ||
<View style={styles.globalNavigationSelectionIndicator(isFocused)} /> | ||
<View style={[styles.flexColumn, styles.flex1, styles.alignItemsCenter, styles.mr1]}> | ||
<Icon | ||
additionalStyles={[styles.popoverMenuIcon]} | ||
pressed={pressed} | ||
src={icon} | ||
fill={isFocused ? StyleUtils.getIconFillColor(CONST.BUTTON_STATES.DEFAULT, true) : StyleUtils.getIconFillColor()} | ||
/> | ||
<View style={[styles.mt1, styles.alignItemsCenter]}> | ||
<Text style={[StyleUtils.getFontSizeStyle(variables.fontSizeExtraSmall), styles.globalNavigationMenuItem(isFocused)]}>{title}</Text> | ||
</View> | ||
</View> | ||
</View> | ||
)} | ||
</PressableWithFeedback> | ||
)); | ||
|
||
GlobalNavigationMenuItem.propTypes = propTypes; | ||
GlobalNavigationMenuItem.defaultProps = defaultProps; | ||
GlobalNavigationMenuItem.displayName = 'GlobalNavigationMenuItem'; | ||
|
||
export default GlobalNavigationMenuItem; |
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,51 @@ | ||
import React, {useMemo, useContext} from 'react'; | ||
import {View} from 'react-native'; | ||
import _ from 'underscore'; | ||
import styles from '../../../../styles/styles'; | ||
import * as Expensicons from '../../../../components/Icon/Expensicons'; | ||
import CONST from '../../../../CONST'; | ||
import Navigation from '../../../../libs/Navigation/Navigation'; | ||
import ROUTES from '../../../../ROUTES'; | ||
import useLocalize from '../../../../hooks/useLocalize'; | ||
import GlobalNavigationMenuItem from './GlobalNavigationMenuItem'; | ||
import {SidebarNavigationContext} from '../SidebarNavigationContext'; | ||
import SignInOrAvatarWithOptionalStatus from '../SignInOrAvatarWithOptionalStatus'; | ||
|
||
function GlobalNavigation() { | ||
const sidebarNavigation = useContext(SidebarNavigationContext); | ||
const {translate} = useLocalize(); | ||
const items = useMemo( | ||
() => [ | ||
{ | ||
icon: Expensicons.ChatBubble, | ||
text: translate('globalNavigationOptions.chats'), | ||
value: CONST.GLOBAL_NAVIGATION_OPTION.CHATS, | ||
onSelected: () => { | ||
Navigation.navigate(ROUTES.REPORT); | ||
}, | ||
}, | ||
], | ||
[translate], | ||
); | ||
|
||
return ( | ||
<View style={[styles.ph5, styles.pv3, styles.alignItemsCenter, styles.h100, styles.globalNavigation]}> | ||
<SignInOrAvatarWithOptionalStatus /> | ||
<View style={styles.globalNavigationMenuContainer}> | ||
{_.map(items, (item) => ( | ||
<GlobalNavigationMenuItem | ||
key={item.value} | ||
icon={item.icon} | ||
title={item.text} | ||
onPress={() => item.onSelected(item.value)} | ||
isFocused={sidebarNavigation.selectedGlobalNavigationOption === item.value} | ||
/> | ||
))} | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
GlobalNavigation.displayName = 'GlobalNavigation'; | ||
|
||
export default GlobalNavigation; |
Oops, something went wrong.