diff --git a/src/CONST.js b/src/CONST.js index c550e4f53e29..ddc1c3f2e620 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -673,7 +673,6 @@ const CONST = { FREE: 'free', PERSONAL: 'personal', CORPORATE: 'corporate', - TEAM: 'team', }, ROLE: { ADMIN: 'admin', diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index a2f9d082e3c3..aecc6912f197 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -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'; @@ -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 { @@ -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; @@ -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; } diff --git a/src/libs/Navigation/AppNavigator/index.js b/src/libs/Navigation/AppNavigator/index.js index b1f53844dcb5..6a7b910ebaef 100644 --- a/src/libs/Navigation/AppNavigator/index.js +++ b/src/libs/Navigation/AppNavigator/index.js @@ -6,9 +6,6 @@ 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 => ( @@ -16,7 +13,7 @@ const AppNavigator = props => ( ? ( // These are the protected screens and only accessible when an authToken is present - + ) : ( diff --git a/src/libs/Navigation/Navigation.js b/src/libs/Navigation/Navigation.js index 7f9328138120..30f6b4ca8399 100644 --- a/src/libs/Navigation/Navigation.js +++ b/src/libs/Navigation/Navigation.js @@ -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, @@ -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, @@ -196,6 +212,8 @@ export default { closeDrawer, getDefaultDrawerState, setDidTapNotification, + isNavigationReady, + setIsNavigationReady, }; export { diff --git a/src/libs/Navigation/NavigationRoot.js b/src/libs/Navigation/NavigationRoot.js index 57fd9ccd0305..1618fea6d3c4 100644 --- a/src/libs/Navigation/NavigationRoot.js +++ b/src/libs/Navigation/NavigationRoot.js @@ -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'; @@ -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 @@ -57,8 +47,7 @@ class NavigationRoot extends Component { } UnreadIndicatorUpdater.throttledUpdatePageTitleAndUnreadCount(); - - this.setState({currentPath}); + Navigation.setIsNavigationReady(); } render() { @@ -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, }} > - + ); } diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 6e98afa085f1..d667e8ee078c 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -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); + }); } } diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 5de94702631d..5716547d1eda 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -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) {