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 @@ -13,6 +13,7 @@ import * as Welcome from '@userActions/Welcome';
import CONST from '@src/CONST';
import NAVIGATORS from '@src/NAVIGATORS';
import SCREENS from '@src/SCREENS';
import syncBrowserHistory from './syncBrowserHistory';
import type {ResponsiveStackNavigatorRouterOptions} from './types';

function insertRootRoute(state: State<RootStackParamList>, routeToInsert: NavigationPartialRoute) {
Expand Down Expand Up @@ -114,11 +115,10 @@ function shouldPreventReset(state: StackNavigationState<ParamListBase>, action:
// We want to prevent the user from navigating back to a non-onboarding screen if they are currently on an onboarding screen
if (isOnboardingFlowName(currentFocusedRoute?.name) && !isOnboardingFlowName(targetFocusedRoute?.name)) {
Welcome.setOnboardingErrorMessage(Localize.translateLocal('onboarding.purpose.errorBackButton'));
// We reset the URL as the browser sets it in a way that doesn't match the navigation state
// eslint-disable-next-line no-restricted-globals
history.replaceState({}, '', getPathFromState(state, linkingConfig.config));
return true;
}

return false;
}

function CustomRouter(options: ResponsiveStackNavigatorRouterOptions) {
Expand All @@ -133,6 +133,7 @@ function CustomRouter(options: ResponsiveStackNavigatorRouterOptions) {
},
getStateForAction(state: StackNavigationState<ParamListBase>, action: CommonActions.Action | StackActionType, configOptions: RouterConfigOptions) {
if (shouldPreventReset(state, action)) {
syncBrowserHistory(state);
return state;
}
return stackRouter.getStateForAction(state, action, configOptions);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import noop from 'lodash/noop';

const syncBrowserHistory = noop;

export default syncBrowserHistory;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type {ParamListBase, StackNavigationState} from '@react-navigation/native';
import {getPathFromState} from '@react-navigation/native';
import linkingConfig from '@libs/Navigation/linkingConfig';

function syncBrowserHistory(state: StackNavigationState<ParamListBase>) {
// We reset the URL as the browser sets it in a way that doesn't match the navigation state
// eslint-disable-next-line no-restricted-globals
history.replaceState({}, '', getPathFromState(state, linkingConfig.config));
}

export default syncBrowserHistory;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {findFocusedRoute, getPathFromState, StackRouter} from '@react-navigation
import type {ParamListBase} from '@react-navigation/routers';
import getIsNarrowLayout from '@libs/getIsNarrowLayout';
import * as Localize from '@libs/Localize';
import syncBrowserHistory from '@libs/Navigation/AppNavigator/createCustomStackNavigator/syncBrowserHistory';
import getTopmostBottomTabRoute from '@libs/Navigation/getTopmostBottomTabRoute';
import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute';
import linkingConfig from '@libs/Navigation/linkingConfig';
Expand Down Expand Up @@ -114,11 +115,10 @@ function shouldPreventReset(state: StackNavigationState<ParamListBase>, action:
// We want to prevent the user from navigating back to a non-onboarding screen if they are currently on an onboarding screen
if (isOnboardingFlowName(currentFocusedRoute?.name) && !isOnboardingFlowName(targetFocusedRoute?.name)) {
Welcome.setOnboardingErrorMessage(Localize.translateLocal('onboarding.purpose.errorBackButton'));
// We reset the URL as the browser sets it in a way that doesn't match the navigation state
// eslint-disable-next-line no-restricted-globals
history.replaceState({}, '', getPathFromState(state, linkingConfig.config));
return true;
}

return false;
}

function CustomRouter(options: PlatformStackRouterOptions) {
Expand All @@ -133,6 +133,7 @@ function CustomRouter(options: PlatformStackRouterOptions) {
},
getStateForAction(state: StackNavigationState<ParamListBase>, action: CommonActions.Action | StackActionType, configOptions: RouterConfigOptions) {
if (shouldPreventReset(state, action)) {
syncBrowserHistory(state);
return state;
}
return stackRouter.getStateForAction(state, action, configOptions);
Expand Down