Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import {
CommonActions, StackActions, DrawerActions, getStateFromPath,
} from '@react-navigation/native';
import lodashGet from 'lodash/get';
import {Dimensions} from 'react-native';
import linkingConfig from './linkingConfig';
import navigationRef from './navigationRef';
import variables from '../../styles/variables';

/**
* @returns {Object}
Expand All @@ -18,6 +16,7 @@ function getActiveState() {

/**
* Go back to the Main Drawer
* @deprecated
* @param {Object} navigationRef
*/
function navigateBackToRootDrawer() {
Expand Down Expand Up @@ -66,14 +65,12 @@ function getScreenNameFromState(state) {
*
* More context here: https://github.com/react-navigation/react-navigation/issues/9744
*
* @deprecated
* @param {String} route
* @returns {Function}
*/
function pushDrawerRoute(route) {
return (currentState) => {
const initialDimensions = Dimensions.get('window');
const isSmallScreenWidth = initialDimensions.width <= variables.mobileResponsiveWidthBreakpoint;

// Parse the state, name, and params from the new route we want to navigate to.
const newStateFromRoute = getStateFromPath(route, linkingConfig.config);
const newScreenName = getScreenNameFromState(newStateFromRoute);
Expand Down Expand Up @@ -108,18 +105,13 @@ function pushDrawerRoute(route) {
// Force drawer to close
// https://github.com/react-navigation/react-navigation/blob/94ab791cae5061455f036cd3f6bc7fa63167e7c7/packages/routers/src/DrawerRouter.tsx#L142
const hasDrawerhistory = _.find(state.history || [], h => h.type === 'drawer');
if (isSmallScreenWidth && (!hasDrawerhistory || currentState.type !== 'drawer')) {
if (!hasDrawerhistory || currentState.type !== 'drawer') {
history.push({
type: 'drawer',

// If current state is not from drawer navigator then always use closed status to close the drawer
status: currentState.type !== 'drawer' || currentState.default === 'open' ? 'closed' : 'open',
});
} else {
history.push({
type: 'route',
name: newScreenName,
});
}

return CommonActions.reset({
Expand Down
6 changes: 3 additions & 3 deletions src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Onyx from 'react-native-onyx';
import Log from '../Log';
import linkTo from './linkTo';
import ROUTES from '../../ROUTES';
import CustomActions from './CustomActions';
import DeprecatedCustomActions from './DeprecatedCustomActions';
import ONYXKEYS from '../../ONYXKEYS';
import linkingConfig from './linkingConfig';
import navigationRef from './navigationRef';
Expand Down Expand Up @@ -140,7 +140,7 @@ function navigate(route = ROUTES.HOME) {
}

if (isDrawerRoute(route)) {
navigationRef.current.dispatch(CustomActions.pushDrawerRoute(route));
navigationRef.current.dispatch(DeprecatedCustomActions.pushDrawerRoute(route));
return;
}

Expand All @@ -161,7 +161,7 @@ function dismissModal(shouldOpenDrawer = false) {
? shouldOpenDrawer
: false;

CustomActions.navigateBackToRootDrawer();
DeprecatedCustomActions.navigateBackToRootDrawer();
if (normalizedShouldOpenDrawer) {
openDrawer();
}
Expand Down