Skip to content

Commit

Permalink
Merge pull request #5131 from parasharrajat/fix-navigation
Browse files Browse the repository at this point in the history
fix: navigation for exisiting report screen
  • Loading branch information
marcaaron authored Oct 18, 2021
2 parents e69f603 + 9cee8d3 commit e5fd8d4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 69 deletions.
39 changes: 38 additions & 1 deletion src/libs/Navigation/CustomActions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
import {CommonActions, StackActions, DrawerActions} from '@react-navigation/native';
import lodashGet from 'lodash/get';

/**
* Go back to the Main Drawer
* @param {Object} navigationRef
*/
function navigateBackToRootDrawer(navigationRef) {
let isLeavingNestedDrawerNavigator = false;

// This should take us to the first view of the modal's stack navigator
navigationRef.current.dispatch((state) => {
// If this is a nested drawer navigator then we pop the screen and
// prevent calling goBack() as it's default behavior is to toggle open the active drawer
if (state.type === 'drawer') {
isLeavingNestedDrawerNavigator = true;
return StackActions.pop();
}

// If there are multiple routes then we can pop back to the first route
if (state.routes.length > 1) {
return StackActions.popToTop();
}

// Otherwise, we are already on the last page of a modal so just do nothing here as goBack() will navigate us
// back to the screen we were on before we opened the modal.
return StackActions.pop(0);
});

if (isLeavingNestedDrawerNavigator) {
return;
}

// Navigate back to where we were before we launched the modal
if (navigationRef.current.canGoBack()) {
navigationRef.current.goBack();
}
}

/**
* In order to create the desired browser navigation behavior on web and mobile web we need to replace any
* type: 'drawer' routes with a type: 'route' so that when pushing to a report screen we never show the
Expand All @@ -24,7 +60,7 @@ function pushDrawerRoute(screenName, params, navigationRef) {

if (activeReportID === params.reportID) {
if (state.type !== 'drawer') {
navigationRef.current.dispatch(StackActions.pop());
navigateBackToRootDrawer(navigationRef);
}
return DrawerActions.closeDrawer();
}
Expand Down Expand Up @@ -52,4 +88,5 @@ function pushDrawerRoute(screenName, params, navigationRef) {

export default {
pushDrawerRoute,
navigateBackToDrawer: navigateBackToRootDrawer,
};
35 changes: 3 additions & 32 deletions src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,39 +138,10 @@ function dismissModal(shouldOpenDrawer = false) {
? shouldOpenDrawer
: false;

let isLeavingDrawerNavigator;

// This should take us to the first view of the modal's stack navigator
navigationRef.current.dispatch((state) => {
// If this is a nested drawer navigator then we pop the screen and
// prevent calling goBack() as it's default behavior is to toggle open the active drawer
if (state.type === 'drawer') {
isLeavingDrawerNavigator = true;
return StackActions.pop();
}

// If there are multiple routes then we can pop back to the first route
if (state.routes.length > 1) {
return StackActions.popToTop();
}

// Otherwise, we are already on the last page of a modal so just do nothing here as goBack() will navigate us
// back to the screen we were on before we opened the modal.
return StackActions.pop(0);
});

if (isLeavingDrawerNavigator) {
return;
CustomActions.navigateBackToDrawer(navigationRef);
if (normalizedShouldOpenDrawer) {
openDrawer();
}

// Navigate back to where we were before we launched the modal
goBack(shouldOpenDrawer);

if (!normalizedShouldOpenDrawer) {
return;
}

openDrawer();
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/pages/ReimbursementAccount/EnableStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class EnableStep extends React.Component {
title: translate('workspace.bankAccount.chatWithConcierge'),
icon: ChatBubble,
onPress: () => {
Navigation.dismissModal();
navigateToConciergeChat();
},
shouldShowRightIcon: true,
Expand Down
10 changes: 2 additions & 8 deletions src/pages/ReimbursementAccount/ValidationStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class ValidationStep extends React.Component {
super(props);

this.submit = this.submit.bind(this);
this.navigateToConcierge = this.navigateToConcierge.bind(this);

this.state = {
amount1: ReimbursementAccountUtils.getDefaultStateForField(props, 'amount1', ''),
Expand Down Expand Up @@ -150,11 +149,6 @@ class ValidationStep extends React.Component {
return value;
}

navigateToConcierge() {
Navigation.dismissModal();
navigateToConciergeChat();
}

render() {
const state = lodashGet(this.props, 'reimbursementAccount.achData.state');

Expand Down Expand Up @@ -182,7 +176,7 @@ class ValidationStep extends React.Component {
{' '}
{this.props.translate('common.please')}
{' '}
<TextLink onPress={this.navigateToConcierge}>
<TextLink onPress={navigateToConciergeChat}>
{this.props.translate('common.contactUs')}
</TextLink>
.
Expand Down Expand Up @@ -237,7 +231,7 @@ class ValidationStep extends React.Component {
menuItems={[{
title: this.props.translate('validationStep.letsChatCTA'),
icon: ChatBubble,
onPress: this.navigateToConcierge,
onPress: navigateToConciergeChat,
shouldShowRightIcon: true,
}]}
>
Expand Down
29 changes: 4 additions & 25 deletions src/pages/settings/AboutPage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import {View, ScrollView} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
Expand All @@ -17,27 +15,17 @@ import {
} from '../../components/Icon/Expensicons';
import ScreenWrapper from '../../components/ScreenWrapper';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import compose from '../../libs/compose';
import MenuItem from '../../components/MenuItem';
import Logo from '../../../assets/images/new-expensify.svg';
import {version} from '../../../package.json';
import {fetchOrCreateChatReport} from '../../libs/actions/Report';
import ONYXKEYS from '../../ONYXKEYS';
import {navigateToConciergeChat} from '../../libs/actions/Report';
import {openExternalLink} from '../../libs/actions/Link';

const propTypes = {
/** Onyx Props */

/** Session info for the currently logged in user. */
session: PropTypes.shape({
/** Currently logged in user email */
email: PropTypes.string,
}).isRequired,

...withLocalizePropTypes,
};

const AboutPage = ({translate, session}) => {
const AboutPage = ({translate}) => {
const menuItems = [
{
translationKey: 'initialSettingsPage.aboutPage.appDownloadLinks',
Expand Down Expand Up @@ -65,9 +53,7 @@ const AboutPage = ({translate, session}) => {
{
translationKey: 'initialSettingsPage.aboutPage.reportABug',
icon: Bug,
action: () => {
fetchOrCreateChatReport([session.email, CONST.EMAIL.CONCIERGE], true);
},
action: navigateToConciergeChat,
},
];

Expand Down Expand Up @@ -159,11 +145,4 @@ const AboutPage = ({translate, session}) => {
AboutPage.propTypes = propTypes;
AboutPage.displayName = 'AboutPage';

export default compose(
withLocalize,
withOnyx({
session: {
key: () => ONYXKEYS.SESSION,
},
}),
)(AboutPage);
export default withLocalize(AboutPage);
2 changes: 0 additions & 2 deletions src/pages/workspace/travel/WorkspaceTravelVBAView.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {RocketOrange} from '../../../components/Icon/Illustrations';
import WorkspaceSection from '../WorkspaceSection';
import {openExternalLink, openOldDotLink} from '../../../libs/actions/Link';
import {navigateToConciergeChat} from '../../../libs/actions/Report';
import Navigation from '../../../libs/Navigation/Navigation';

const propTypes = {
...withLocalizePropTypes,
Expand All @@ -34,7 +33,6 @@ const WorkspaceTravelVBAView = ({translate}) => (
{
title: translate('workspace.travel.bookTravelWithConcierge'),
onPress: () => {
Navigation.dismissModal();
navigateToConciergeChat();
},
icon: Concierge,
Expand Down

0 comments on commit e5fd8d4

Please sign in to comment.