diff --git a/src/CONST.js b/src/CONST.js index c0e26e78fca7..e8c9d4b93a79 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -696,6 +696,11 @@ const CONST = { // There's a limit of 60k characters in Auth - https://github.com/Expensify/Auth/blob/198d59547f71fdee8121325e8bc9241fc9c3236a/auth/lib/Request.h#L28 MAX_COMMENT_LENGTH: 60000, + + DRAWER_STATUS: { + OPEN: 'open', + CLOSED: 'closed', + }, }; export default CONST; diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index e3ec98b6052e..6426297e2ce6 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -193,4 +193,7 @@ export default { // Validating Email? USER_SIGN_UP: 'userSignUp', + + // Store default drawer status + DEFAULT_DRAWER_STATUS: 'defaultDrawerStatus', }; diff --git a/src/libs/Navigation/AppNavigator/BaseDrawerNavigator.js b/src/libs/Navigation/AppNavigator/BaseDrawerNavigator.js index e90d35a6cd6c..364659d461ff 100644 --- a/src/libs/Navigation/AppNavigator/BaseDrawerNavigator.js +++ b/src/libs/Navigation/AppNavigator/BaseDrawerNavigator.js @@ -6,6 +6,7 @@ import {View} from 'react-native'; import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions'; import styles from '../../../styles/styles'; import * as StyleUtils from '../../../styles/StyleUtils'; +import * as App from '../../actions/App'; import Navigation from '../Navigation'; @@ -66,6 +67,19 @@ class BaseDrawerNavigator extends Component { ), swipeEdgeWidth: 500, }} + screenListeners={{ + state: (e) => { + const state = e.data.state; + + // Get the history that has drawer type to get the status. + const hasDrawerHistory = _.find(state.history || [], h => h.type === 'drawer'); + + // hasDrawerHistory will has undefined value if the route drawer is equal to initial route drawer. + // Using the default status if hasDrawerHistory is undefined and get the status from the current route + // if the value provided. + App.setDefaultDrawerStatus(hasDrawerHistory ? hasDrawerHistory.status : state.default); + }, + }} > {_.map(this.props.screens, screen => ( isLoggedIn = Boolean(val && val.authToken), }); +let defaultDrawerStatus = CONST.DRAWER_STATUS.OPEN; +Onyx.connect({ + key: ONYXKEYS.DEFAULT_DRAWER_STATUS, + callback: val => defaultDrawerStatus = val, +}); + // This flag indicates that we're trying to deeplink to a report when react-navigation is not fully loaded yet. // If true, this flag will cause the drawer to start in a closed state (which is not the default for small screens) // so it doesn't cover the report we're trying to link to. @@ -74,9 +81,18 @@ function closeDrawer() { */ function getDefaultDrawerState(isSmallScreenWidth) { if (didTapNotificationBeforeReady) { - return 'closed'; + return CONST.DRAWER_STATUS.CLOSED; } - return isSmallScreenWidth ? 'open' : 'closed'; + + if (isSmallScreenWidth) { + const path = getPathFromState(navigationRef.current.getState(), linkingConfig.config); + + // If the initial route path is HOME SCREEN, + // return open for default status drawer instead of using value from Onyx + return path === '/' ? CONST.DRAWER_STATUS.OPEN : defaultDrawerStatus; + } + + return CONST.DRAWER_STATUS.CLOSED; } /** diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index a5d8918d6404..93e865665b6e 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -135,6 +135,14 @@ function fixAccountAndReloadData() { }); } +/** + * Store drawer status to Onyx + * @param {String} defaultDrawerStatus + */ +function setDefaultDrawerStatus(defaultDrawerStatus) { + Onyx.set(ONYXKEYS.DEFAULT_DRAWER_STATUS, defaultDrawerStatus); +} + // When the app reconnects from being offline, fetch all initialization data NetworkConnection.onReconnect(() => getAppData(true, false)); @@ -142,6 +150,7 @@ export { setCurrentURL, setLocale, setSidebarLoaded, + setDefaultDrawerStatus, getLocale, getAppData, fixAccountAndReloadData,