-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9410348
commit 8549d41
Showing
13 changed files
with
139 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/libs/Navigation/linkTo/helpers/areNamesAndParamsEqual.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {findFocusedRoute} from '@react-navigation/native'; | ||
import type {NavigationState, PartialState} from '@react-navigation/native'; | ||
import type {RootStackParamList} from '@libs/Navigation/types'; | ||
import {shallowCompare} from '@libs/ObjectUtils'; | ||
|
||
// Compare this and next state to determine if focused route names and params are equal. | ||
function areNamesAndParamsEqual(currentState: NavigationState<RootStackParamList>, stateFromPath: PartialState<NavigationState<RootStackParamList>>) { | ||
const currentFocusedRoute = findFocusedRoute(currentState); | ||
const targetFocusedRoute = findFocusedRoute(stateFromPath); | ||
|
||
const areNamesEqual = currentFocusedRoute?.name === targetFocusedRoute?.name; | ||
const areParamsEqual = shallowCompare(currentFocusedRoute?.params as Record<string, unknown> | undefined, targetFocusedRoute?.params as Record<string, unknown> | undefined); | ||
|
||
return areNamesEqual && areParamsEqual; | ||
} | ||
export default areNamesAndParamsEqual; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type {NavigationPartialRoute, ReportsSplitNavigatorParamList, SearchReportParamList} from '@libs/Navigation/types'; | ||
import ROUTES from '@src/ROUTES'; | ||
import SCREENS from '@src/SCREENS'; | ||
|
||
// We have two types of report screens. One is in the search central pane and the other is in the right hand pane. | ||
// This functions converts the path to the opposite form. | ||
function convertReportPath(focusedRouteFromPath: NavigationPartialRoute) { | ||
const params = focusedRouteFromPath.params as ReportsSplitNavigatorParamList[typeof SCREENS.REPORT] | SearchReportParamList[typeof SCREENS.SEARCH.REPORT_RHP]; | ||
if (focusedRouteFromPath.name === SCREENS.REPORT) { | ||
return ROUTES.SEARCH_REPORT.getRoute({reportID: params.reportID, reportActionID: params.reportActionID}); | ||
} | ||
|
||
return ROUTES.REPORT_WITH_ID.getRoute(params.reportID, params.reportActionID); | ||
} | ||
|
||
export default convertReportPath; |
21 changes: 21 additions & 0 deletions
21
src/libs/Navigation/linkTo/helpers/createActionWithPolicyID.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type {StackActionType} from '@react-navigation/native'; | ||
|
||
// Add policyID to the action payload | ||
function createActionWithPolicyID(action: StackActionType, policyID: string): StackActionType | undefined { | ||
if (action.type !== 'PUSH' && action.type !== 'REPLACE') { | ||
return; | ||
} | ||
|
||
return { | ||
...action, | ||
payload: { | ||
...action.payload, | ||
params: { | ||
...action.payload.params, | ||
policyID, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
export default createActionWithPolicyID; |
2 changes: 1 addition & 1 deletion
2
.../linkTo/getActionForBottomTabNavigator.ts → ...helpers/getActionForBottomTabNavigator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/libs/Navigation/linkTo/helpers/isNavigatingToAttachmentScreen.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import SCREENS from '@src/SCREENS'; | ||
|
||
function isNavigatingToAttachmentScreen(focusedRouteName?: string) { | ||
return focusedRouteName === SCREENS.ATTACHMENTS; | ||
} | ||
|
||
export default isNavigatingToAttachmentScreen; |
20 changes: 20 additions & 0 deletions
20
src/libs/Navigation/linkTo/helpers/isNavigatingToReportWithSameReportID.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type {NavigationPartialRoute, ReportsSplitNavigatorParamList} from '@libs/Navigation/types'; | ||
import SCREENS from '@src/SCREENS'; | ||
|
||
// Report screen is a specific case. We want to PUSH if the reportID is different. | ||
// But if only the reportActionID is different we want to NAVIGATE. | ||
// We don't want to push report with the same reportID on the browser history stack. | ||
function isNavigatingToReportWithSameReportID(currentRoute: NavigationPartialRoute, newRoute: NavigationPartialRoute) { | ||
if (currentRoute.name !== SCREENS.REPORT || newRoute.name !== SCREENS.REPORT) { | ||
return false; | ||
} | ||
|
||
const currentParams = currentRoute.params as ReportsSplitNavigatorParamList[typeof SCREENS.REPORT]; | ||
type NewType = ReportsSplitNavigatorParamList; | ||
|
||
const newParams = newRoute?.params as NewType[typeof SCREENS.REPORT]; | ||
|
||
return currentParams.reportID === newParams.reportID; | ||
} | ||
|
||
export default isNavigatingToReportWithSameReportID; |
10 changes: 10 additions & 0 deletions
10
src/libs/Navigation/linkTo/helpers/shouldCheckFullScreenRouteMatching.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type {StackNavigationAction} from '@libs/Navigation/types'; | ||
import NAVIGATORS from '@src/NAVIGATORS'; | ||
|
||
// We need to check if the screen displayed under the overlay matches the contend of modal navigator if we navigate to a modal navigator screen. | ||
// Currently it's only for the RHP because screens in LHP matches to any content. | ||
function shouldCheckFullScreenRouteMatching(action: StackNavigationAction): action is StackNavigationAction & {type: 'PUSH'; payload: {name: typeof NAVIGATORS.RIGHT_MODAL_NAVIGATOR}} { | ||
return action !== undefined && action.type === 'PUSH' && action.payload.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR; | ||
} | ||
|
||
export default shouldCheckFullScreenRouteMatching; |
18 changes: 18 additions & 0 deletions
18
src/libs/Navigation/linkTo/helpers/shouldConvertReportPath.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type {NavigationPartialRoute} from '@libs/Navigation/types'; | ||
import SCREENS from '@src/SCREENS'; | ||
|
||
// Determine if we should convert the report route from fullscreen to rhp version or the other way around. | ||
// It's necessary to stay in RHP if we are in RHP report or in fullscreen if we are in fullscreen report. | ||
function shouldConvertReportPath(currentFocusedRoute: NavigationPartialRoute, focusedRouteFromPath: NavigationPartialRoute) { | ||
// @TODO: Navigating from search central pane could be handled with explicit convert: false option. We would need to add it as option to linkTo. | ||
if (focusedRouteFromPath.name === SCREENS.REPORT && (currentFocusedRoute.name === SCREENS.SEARCH.REPORT_RHP || currentFocusedRoute.name === SCREENS.SEARCH.CENTRAL_PANE)) { | ||
return true; | ||
} | ||
|
||
if (focusedRouteFromPath.name === SCREENS.SEARCH.REPORT_RHP && currentFocusedRoute.name === SCREENS.REPORT) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
export default shouldConvertReportPath; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters