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
11 changes: 1 addition & 10 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 @@ -88,9 +87,6 @@ const modalScreenListeners = {

const propTypes = {
...windowDimensionsPropTypes,

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

class AuthScreens extends React.Component {
Expand Down Expand Up @@ -118,7 +114,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 @@ -136,11 +132,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
24 changes: 6 additions & 18 deletions src/libs/Navigation/NavigationRoot.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {getPathFromState, NavigationContainer, DefaultTheme} from '@react-navigation/native';
import {NavigationContainer, DefaultTheme, getPathFromState} from '@react-navigation/native';
import * as Navigation from './Navigation';
import linkingConfig from './linkingConfig';
import AppNavigator from './AppNavigator';
import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator';
import Log from '../Log';
import colors from '../../styles/colors';
import styles from '../../styles/styles';
import Log from '../Log';

// https://reactnavigation.org/docs/themes
const navigationTheme = {
Expand All @@ -27,21 +27,11 @@ const propTypes = {
};

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

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

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

/**
* Intercept state changes and perform different logic
* Intercept navigation state changes and log it
* @param {NavigationState} state
*/
parseAndStoreRoute(state) {
parseAndLogRoute(state) {
if (!state) {
return;
}
Expand All @@ -54,8 +44,6 @@ class NavigationRoot extends Component {
} else {
Log.info('Navigating to route', false, {path: currentPath});
}
Comment thread
arosiclair marked this conversation as resolved.

this.setState({currentPath});
}

render() {
Expand All @@ -67,7 +55,7 @@ class NavigationRoot extends Component {
style={styles.navigatorFullScreenLoading}
/>
)}
onStateChange={this.parseAndStoreRoute}
onStateChange={this.parseAndLogRoute}
onReady={this.props.onReady}
theme={navigationTheme}
ref={Navigation.navigationRef}
Expand All @@ -76,7 +64,7 @@ class NavigationRoot extends Component {
enabled: false,
}}
>
<AppNavigator authenticated={this.props.authenticated} currentPath={this.state.currentPath} />
<AppNavigator authenticated={this.props.authenticated} />
</NavigationContainer>
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/libs/Navigation/currentUrl/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @returns {String}
*/
export default function getCurrentUrl() {
Comment thread
arosiclair marked this conversation as resolved.
return window.location.href;
}
6 changes: 6 additions & 0 deletions src/libs/Navigation/currentUrl/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @returns {String}
*/
export default function getCurrentUrl() {
Comment thread
arosiclair marked this conversation as resolved.
return '';
}
22 changes: 8 additions & 14 deletions src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as Policy from './Policy';
import Navigation from '../Navigation/Navigation';
import ROUTES from '../../ROUTES';
import * as SessionUtils from '../SessionUtils';
import getCurrentUrl from '../Navigation/currentUrl';

let currentUserAccountID;
let currentUserEmail = '';
Expand Down Expand Up @@ -161,26 +162,19 @@ function reconnectApp() {
* pass it in as a parameter. withOnyx guarantees that the value has been read
* from Onyx because it will not render the AuthScreens until that point.
* @param {Object} session
* @param {string} currentPath
*/
function setUpPoliciesAndNavigate(session, currentPath) {
if (!session || !currentPath || !currentPath.includes('exitTo')) {
function setUpPoliciesAndNavigate(session) {
const currentUrl = getCurrentUrl();
if (!session || !currentUrl || !currentUrl.includes('exitTo')) {
return;
}

let exitTo;
try {
const url = new URL(currentPath, CONST.NEW_EXPENSIFY_URL);
exitTo = url.searchParams.get('exitTo');
} catch (error) {
// URLSearchParams is unsupported on iOS so we catch th error and
// silence it here since this is primarily a Web flow
return;
}
const isLoggingInAsNewUser = SessionUtils.isLoggingInAsNewUser(currentUrl, session.email);
const url = new URL(currentUrl);
const exitTo = url.searchParams.get('exitTo');

const isLoggingInAsNewUser = SessionUtils.isLoggingInAsNewUser(currentPath, session.email);
const shouldCreateFreePolicy = !isLoggingInAsNewUser
&& Str.startsWith(currentPath, Str.normalizeUrl(ROUTES.TRANSITION_FROM_OLD_DOT))
&& Str.startsWith(url.pathname, Str.normalizeUrl(ROUTES.TRANSITION_FROM_OLD_DOT))
&& exitTo === ROUTES.WORKSPACE_NEW;
if (shouldCreateFreePolicy) {
Policy.createAndGetPolicyList();
Expand Down