Skip to content

Commit

Permalink
move navigate types to const
Browse files Browse the repository at this point in the history
Signed-off-by: Yauheni Pasiukevich <pasyukevich@live.com>
  • Loading branch information
pasyukevich committed Aug 14, 2023
1 parent d63c4cf commit b915573
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
11 changes: 11 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,17 @@ const CONST = {
DISTANCE: 'distance',
},
STATUS_TEXT_MAX_LENGTH: 100,
NAVIGATION: {
TYPE: {
FORCED_UP: 'FORCED_UP',
UP: 'UP',
},
ACTION_TYPE: {
REPLACE: 'REPLACE',
PUSH: 'PUSH',
NAVIGATE: 'NAVIGATE',
},
},
};

export default CONST;
3 changes: 2 additions & 1 deletion src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import NAVIGATORS from '../../NAVIGATORS';
import originalGetTopmostReportId from './getTopmostReportId';
import getStateFromPath from './getStateFromPath';
import SCREENS from '../../SCREENS';
import CONST from '../../CONST';

let resolveNavigationIsReadyPromise;
const navigationIsReadyPromise = new Promise((resolve) => {
Expand Down Expand Up @@ -127,7 +128,7 @@ function goBack(fallbackRoute = ROUTES.HOME, shouldEnforceFallback = false, shou
}

if (shouldEnforceFallback || (isFirstRouteInNavigator && fallbackRoute)) {
navigate(fallbackRoute, 'UP');
navigate(fallbackRoute, CONST.NAVIGATION.TYPE.UP);
return;
}

Expand Down
15 changes: 8 additions & 7 deletions src/libs/Navigation/linkTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import NAVIGATORS from '../../NAVIGATORS';
import linkingConfig from './linkingConfig';
import getTopmostReportId from './getTopmostReportId';
import getStateFromPath from './getStateFromPath';
import CONST from '../../CONST';

/**
* Motivation for this function is described in NAVIGATION.md
Expand Down Expand Up @@ -59,23 +60,23 @@ export default function linkTo(navigation, path, type) {
const action = getActionFromState(state, linkingConfig.config);

// If action type is different than NAVIGATE we can't change it to the PUSH safely
if (action.type === 'NAVIGATE') {
if (action.type === CONST.NAVIGATION.ACTION_TYPE.NAVIGATE) {
// In case if type is 'FORCED_UP' we ensure that we need to replace current screen to the provided
if (type === 'FORCED_UP') {
action.type = 'REPLACE';
if (type === CONST.NAVIGATION.TYPE.FORCED_UP) {
action.type = CONST.NAVIGATION.ACTION_TYPE.REPLACE;

// If this action is navigating to the report screen and the top most navigator is different from the one we want to navigate - PUSH
} else if (action.payload.name === NAVIGATORS.CENTRAL_PANE_NAVIGATOR && getTopmostReportId(root.getState()) !== getTopmostReportId(state)) {
action.type = 'PUSH';
action.type = CONST.NAVIGATION.ACTION_TYPE.PUSH;

// If the type is UP, we deeplinked into one of the RHP flows and we want to replace the current screen with the previous one in the flow
// and at the same time we want the back button to go to the page we were before the deeplink
} else if (type === 'UP') {
action.type = 'REPLACE';
} else if (type === CONST.NAVIGATION.TYPE.UP) {
action.type = CONST.NAVIGATION.ACTION_TYPE.REPLACE;

// If this action is navigating to the RightModalNavigator and the last route on the root navigator is not RightModalNavigator then push
} else if (action.payload.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR && _.last(root.getState().routes).name !== NAVIGATORS.RIGHT_MODAL_NAVIGATOR) {
action.type = 'PUSH';
action.type = CONST.NAVIGATION.ACTION_TYPE.PUSH;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ function handleReportChanged(report) {
// Only re-route them if they are still looking at the optimistically created report
if (Navigation.getActiveRoute().includes(`/r/${report.reportID}`)) {
// Pass 'FORCED_UP' type to replace new report on second login with proper one in the Navigation
Navigation.navigate(ROUTES.getReportRoute(report.preexistingReportID), 'FORCED_UP');
Navigation.navigate(ROUTES.getReportRoute(report.preexistingReportID), CONST.NAVIGATION.TYPE.FORCED_UP);
}
return;
}
Expand Down Expand Up @@ -1734,7 +1734,7 @@ function openReportFromDeepLink(url, isAuthenticated) {
InteractionManager.runAfterInteractions(() => {
SidebarUtils.isSidebarLoadedReady().then(() => {
if (reportID) {
Navigation.navigate(ROUTES.getReportRoute(reportID), 'UP');
Navigation.navigate(ROUTES.getReportRoute(reportID), CONST.NAVIGATION.TYPE.UP);
}
if (route === ROUTES.CONCIERGE) {
navigateToConciergeChat();
Expand Down

0 comments on commit b915573

Please sign in to comment.