Skip to content

Commit

Permalink
Merge pull request #10949 from Expensify/arosiclair-transition-fix
Browse files Browse the repository at this point in the history
Fix transitions to existing workspaces from OldDot
  • Loading branch information
neil-marcellini authored Sep 22, 2022
2 parents 951920b + 83a011f commit 86cae9b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 32 deletions.
1 change: 0 additions & 1 deletion src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,6 @@ const CONST = {
FREE: 'free',
PERSONAL: 'personal',
CORPORATE: 'corporate',
TEAM: 'team',
},
ROLE: {
ADMIN: 'admin',
Expand Down
9 changes: 1 addition & 8 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Onyx, {withOnyx} from 'react-native-onyx';
import moment from 'moment';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import * as StyleUtils from '../../../styles/StyleUtils';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import CONST from '../../../CONST';
Expand Down Expand Up @@ -87,9 +86,6 @@ const modalScreenListeners = {

const propTypes = {
...windowDimensionsPropTypes,

/** The current path as reported by the NavigationContainer */
currentPath: PropTypes.string.isRequired,
};

class AuthScreens extends React.Component {
Expand All @@ -116,6 +112,7 @@ class AuthScreens extends React.Component {
// Listen for report changes and fetch some data we need on initialization
UnreadIndicatorUpdater.listenForReportChanges();
App.openApp();
App.setUpPoliciesAndNavigate(this.props.session);
Timing.end(CONST.TIMING.HOMEPAGE_INITIAL_RENDER);

const searchShortcutConfig = CONST.KEYBOARD_SHORTCUTS.SEARCH;
Expand All @@ -133,10 +130,6 @@ class AuthScreens extends React.Component {
}

shouldComponentUpdate(nextProps) {
// we perform this check here instead of componentDidUpdate to skip an unnecessary re-render
if (this.props.currentPath !== nextProps.currentPath) {
App.setUpPoliciesAndNavigate(nextProps.session, nextProps.currentPath);
}
return nextProps.isSmallScreenWidth !== this.props.isSmallScreenWidth;
}

Expand Down
5 changes: 1 addition & 4 deletions src/libs/Navigation/AppNavigator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ import AuthScreens from './AuthScreens';
const propTypes = {
/** If we have an authToken this is true */
authenticated: PropTypes.bool.isRequired,

/** The current path as reported by the NavigationContainer */
currentPath: PropTypes.string.isRequired,
};

const AppNavigator = props => (
props.authenticated
? (

// These are the protected screens and only accessible when an authToken is present
<AuthScreens currentPath={props.currentPath} />
<AuthScreens />
)
: (
<PublicScreens />
Expand Down
18 changes: 18 additions & 0 deletions src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import ONYXKEYS from '../../ONYXKEYS';
import linkingConfig from './linkingConfig';
import navigationRef from './navigationRef';

let resolveNavigationIsReadyPromise;
const navigationIsReadyPromise = new Promise((resolve) => {
resolveNavigationIsReadyPromise = resolve;
});

let isLoggedIn = false;
Onyx.connect({
key: ONYXKEYS.SESSION,
Expand Down Expand Up @@ -186,6 +191,17 @@ function isActiveRoute(routePath) {
return getActiveRoute().substring(1) === routePath;
}

/**
* @returns {Promise}
*/
function isNavigationReady() {
return navigationIsReadyPromise;
}

function setIsNavigationReady() {
resolveNavigationIsReadyPromise();
}

export default {
canNavigate,
navigate,
Expand All @@ -196,6 +212,8 @@ export default {
closeDrawer,
getDefaultDrawerState,
setDidTapNotification,
isNavigationReady,
setIsNavigationReady,
};

export {
Expand Down
19 changes: 4 additions & 15 deletions src/libs/Navigation/NavigationRoot.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {NavigationContainer, DefaultTheme, getPathFromState} from '@react-navigation/native';
import * as Navigation from './Navigation';
import Navigation, {navigationRef} from './Navigation';
import linkingConfig from './linkingConfig';
import AppNavigator from './AppNavigator';
import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator';
Expand All @@ -28,16 +28,6 @@ const propTypes = {
};

class NavigationRoot extends Component {
constructor(props) {
super(props);

this.state = {
currentPath: '',
};

this.parseAndLogRoute = this.parseAndLogRoute.bind(this);
}

/**
* Intercept navigation state changes and log it
* @param {NavigationState} state
Expand All @@ -57,8 +47,7 @@ class NavigationRoot extends Component {
}

UnreadIndicatorUpdater.throttledUpdatePageTitleAndUnreadCount();

this.setState({currentPath});
Navigation.setIsNavigationReady();
}

render() {
Expand All @@ -73,13 +62,13 @@ class NavigationRoot extends Component {
onStateChange={this.parseAndLogRoute}
onReady={this.props.onReady}
theme={navigationTheme}
ref={Navigation.navigationRef}
ref={navigationRef}
linking={linkingConfig}
documentTitle={{
enabled: false,
}}
>
<AppNavigator authenticated={this.props.authenticated} currentPath={this.state.currentPath} />
<AppNavigator authenticated={this.props.authenticated} />
</NavigationContainer>
);
}
Expand Down
9 changes: 6 additions & 3 deletions src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,12 @@ function setUpPoliciesAndNavigate(session) {
return;
}
if (!isLoggingInAsNewUser && exitTo) {
// We must call dismissModal() to remove the /transition route from history
Navigation.dismissModal();
Navigation.navigate(exitTo);
Navigation.isNavigationReady()
.then(() => {
// We must call dismissModal() to remove the /transition route from history
Navigation.dismissModal();
Navigation.navigate(exitTo);
});
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,11 @@ function createWorkspace() {
}],
});

Navigation.navigate(ROUTES.getWorkspaceInitialRoute(policyID));
Navigation.isNavigationReady()
.then(() => {
Navigation.dismissModal(); // Dismiss /transition route for OldDot to NewDot transitions
Navigation.navigate(ROUTES.getWorkspaceInitialRoute(policyID));
});
}

function openWorkspaceReimburseView(policyID) {
Expand Down

0 comments on commit 86cae9b

Please sign in to comment.