-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33499 from software-mansion-labs/lhp-ideal-nav
- Loading branch information
Showing
15 changed files
with
195 additions
and
74 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
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
45 changes: 45 additions & 0 deletions
45
src/libs/Navigation/AppNavigator/Navigators/LeftModalNavigator.tsx
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,45 @@ | ||
import {createStackNavigator, StackScreenProps} from '@react-navigation/stack'; | ||
import React, {useMemo} from 'react'; | ||
import {View} from 'react-native'; | ||
import NoDropZone from '@components/DragAndDrop/NoDropZone'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
import ModalNavigatorScreenOptions from '@libs/Navigation/AppNavigator/ModalNavigatorScreenOptions'; | ||
import * as ModalStackNavigators from '@libs/Navigation/AppNavigator/ModalStackNavigators'; | ||
import {AuthScreensParamList, LeftModalNavigatorParamList} from '@libs/Navigation/types'; | ||
import NAVIGATORS from '@src/NAVIGATORS'; | ||
import SCREENS from '@src/SCREENS'; | ||
import Overlay from './Overlay'; | ||
|
||
type LeftModalNavigatorProps = StackScreenProps<AuthScreensParamList, typeof NAVIGATORS.LEFT_MODAL_NAVIGATOR>; | ||
|
||
const Stack = createStackNavigator<LeftModalNavigatorParamList>(); | ||
|
||
function LeftModalNavigator({navigation}: LeftModalNavigatorProps) { | ||
const styles = useThemeStyles(); | ||
const {isSmallScreenWidth} = useWindowDimensions(); | ||
const screenOptions = useMemo(() => ModalNavigatorScreenOptions(styles), [styles]); | ||
|
||
return ( | ||
<NoDropZone> | ||
{!isSmallScreenWidth && ( | ||
<Overlay | ||
isModalOnTheLeft | ||
onPress={navigation.goBack} | ||
/> | ||
)} | ||
<View style={styles.LHPNavigatorContainer(isSmallScreenWidth)}> | ||
<Stack.Navigator screenOptions={screenOptions}> | ||
<Stack.Screen | ||
name={SCREENS.LEFT_MODAL.SEARCH} | ||
component={ModalStackNavigators.SearchModalStackNavigator} | ||
/> | ||
</Stack.Navigator> | ||
</View> | ||
</NoDropZone> | ||
); | ||
} | ||
|
||
LeftModalNavigator.displayName = 'LeftModalNavigator'; | ||
|
||
export default LeftModalNavigator; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {getActionFromState} from '@react-navigation/core'; | ||
import {NavigationContainerRef, StackActions} from '@react-navigation/native'; | ||
import {findLastIndex} from 'lodash'; | ||
import Log from '@libs/Log'; | ||
import NAVIGATORS from '@src/NAVIGATORS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import SCREENS from '@src/SCREENS'; | ||
import getStateFromPath from './getStateFromPath'; | ||
import getTopmostReportId from './getTopmostReportId'; | ||
import linkingConfig from './linkingConfig'; | ||
import {RootStackParamList, StackNavigationAction} from './types'; | ||
|
||
// This function is in a separate file than Navigation.js to avoid cyclic dependency. | ||
|
||
/** | ||
* Dismisses the last modal stack if there is any | ||
* | ||
* @param targetReportID - The reportID to navigate to after dismissing the modal | ||
*/ | ||
function dismissModal(targetReportID: string, navigationRef: NavigationContainerRef<RootStackParamList>) { | ||
if (!navigationRef.isReady()) { | ||
return; | ||
} | ||
|
||
const state = navigationRef.getState(); | ||
const lastRoute = state.routes.at(-1); | ||
switch (lastRoute?.name) { | ||
case NAVIGATORS.LEFT_MODAL_NAVIGATOR: | ||
case NAVIGATORS.RIGHT_MODAL_NAVIGATOR: | ||
case SCREENS.NOT_FOUND: | ||
case SCREENS.REPORT_ATTACHMENTS: | ||
// if we are not in the target report, we need to navigate to it after dismissing the modal | ||
if (targetReportID && targetReportID !== getTopmostReportId(state)) { | ||
const reportState = getStateFromPath(ROUTES.REPORT_WITH_ID.getRoute(targetReportID)); | ||
|
||
const action: StackNavigationAction = getActionFromState(reportState, linkingConfig.config); | ||
if (action) { | ||
action.type = 'REPLACE'; | ||
navigationRef.dispatch(action); | ||
} | ||
// If not-found page is in the route stack, we need to close it | ||
} else if (targetReportID && state.routes.some((route) => route.name === SCREENS.NOT_FOUND)) { | ||
const lastRouteIndex = state.routes.length - 1; | ||
const centralRouteIndex = findLastIndex(state.routes, (route) => route.name === NAVIGATORS.CENTRAL_PANE_NAVIGATOR); | ||
navigationRef.dispatch({...StackActions.pop(lastRouteIndex - centralRouteIndex), target: state.key}); | ||
} else { | ||
navigationRef.dispatch({...StackActions.pop(), target: state.key}); | ||
} | ||
break; | ||
default: { | ||
Log.hmmm('[Navigation] dismissModal failed because there is no modal stack to dismiss'); | ||
} | ||
} | ||
} | ||
|
||
export default dismissModal; |
Oops, something went wrong.