Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Create platform specific syncBrowserHistory function #50719

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another file that requires same fix src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/CustomRouter.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I forgot that we merged the native stack. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, probably need to replicate these changes in native-stack navigator as well 👍

@adamgrzybowski will you do that in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm actually isn't this some leftover after merging the native stack? I think that createResponsiveStackNavigator isn't used anywhere

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm actually isn't this some leftover after merging the native stack? I think that createResponsiveStackNavigator isn't used anywhere

@adamgrzybowski it's not used at the moment, because we decided to split PR in two parts (the first one is with all basic work (i. e. creation of new navigators), new patches etc.) and the other one that actually starts to use it: #49937

But I think it would be better to synchronize all new changes between various navigators, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in that case, I will apply the changes for both routers. Thanks!

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/index.web';
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;
Loading