-
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.
Merge pull request #30279 from adamgrzybowski/@swm/limit-report-route…
…s-number Limit report routes in the customStackNavigator
- Loading branch information
Showing
6 changed files
with
150 additions
and
38 deletions.
There are no files selected for viewing
36 changes: 0 additions & 36 deletions
36
src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator.js
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/BaseCentralPaneNavigator.js
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,33 @@ | ||
import {createStackNavigator} from '@react-navigation/stack'; | ||
import React from 'react'; | ||
import ReportScreenWrapper from '@libs/Navigation/AppNavigator/ReportScreenWrapper'; | ||
import getCurrentUrl from '@libs/Navigation/currentUrl'; | ||
import styles from '@styles/styles'; | ||
import SCREENS from '@src/SCREENS'; | ||
|
||
const Stack = createStackNavigator(); | ||
|
||
const url = getCurrentUrl(); | ||
const openOnAdminRoom = url ? new URL(url).searchParams.get('openOnAdminRoom') : undefined; | ||
|
||
function BaseCentralPaneNavigator() { | ||
return ( | ||
<Stack.Navigator> | ||
<Stack.Screen | ||
name={SCREENS.REPORT} | ||
// We do it this way to avoid adding the url params to url | ||
initialParams={{openOnAdminRoom: openOnAdminRoom === 'true' || undefined}} | ||
options={{ | ||
headerShown: false, | ||
title: 'New Expensify', | ||
|
||
// Prevent unnecessary scrolling | ||
cardStyle: styles.cardStyleNavigator, | ||
}} | ||
component={ReportScreenWrapper} | ||
/> | ||
</Stack.Navigator> | ||
); | ||
} | ||
|
||
export default BaseCentralPaneNavigator; |
10 changes: 10 additions & 0 deletions
10
src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/index.js
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 React from 'react'; | ||
import BaseCentralPaneNavigator from './BaseCentralPaneNavigator'; | ||
|
||
// We don't need to use freeze wraper on web because we don't render all report routes anyway. | ||
// You can see this optimalization in the customStackNavigator. | ||
function CentralPaneNavigator() { | ||
return <BaseCentralPaneNavigator />; | ||
} | ||
|
||
export default CentralPaneNavigator; |
13 changes: 13 additions & 0 deletions
13
src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/index.native.js
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,13 @@ | ||
import React from 'react'; | ||
import FreezeWrapper from '@libs/Navigation/FreezeWrapper'; | ||
import BaseCentralPaneNavigator from './BaseCentralPaneNavigator'; | ||
|
||
function CentralPaneNavigator() { | ||
return ( | ||
<FreezeWrapper> | ||
<BaseCentralPaneNavigator /> | ||
</FreezeWrapper> | ||
); | ||
} | ||
|
||
export default CentralPaneNavigator; |
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
60 changes: 60 additions & 0 deletions
60
src/libs/Navigation/AppNavigator/createCustomStackNavigator/index.native.js
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,60 @@ | ||
import {createNavigatorFactory, useNavigationBuilder} from '@react-navigation/native'; | ||
import {StackView} from '@react-navigation/stack'; | ||
import PropTypes from 'prop-types'; | ||
import React, {useRef} from 'react'; | ||
import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
import CustomRouter from './CustomRouter'; | ||
|
||
const propTypes = { | ||
/* Determines if the navigator should render the StackView (narrow) or ThreePaneView (wide) */ | ||
isSmallScreenWidth: PropTypes.bool.isRequired, | ||
|
||
/* Children for the useNavigationBuilder hook */ | ||
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]).isRequired, | ||
|
||
/* initialRouteName for this navigator */ | ||
initialRouteName: PropTypes.oneOf([PropTypes.string, PropTypes.undefined]), | ||
|
||
/* Screen options defined for this navigator */ | ||
// eslint-disable-next-line react/forbid-prop-types | ||
screenOptions: PropTypes.object, | ||
}; | ||
|
||
const defaultProps = { | ||
initialRouteName: undefined, | ||
screenOptions: undefined, | ||
}; | ||
|
||
function ResponsiveStackNavigator(props) { | ||
const {isSmallScreenWidth} = useWindowDimensions(); | ||
|
||
const isSmallScreenWidthRef = useRef(isSmallScreenWidth); | ||
|
||
isSmallScreenWidthRef.current = isSmallScreenWidth; | ||
|
||
const {navigation, state, descriptors, NavigationContent} = useNavigationBuilder(CustomRouter, { | ||
children: props.children, | ||
screenOptions: props.screenOptions, | ||
initialRouteName: props.initialRouteName, | ||
// Options for useNavigationBuilder won't update on prop change, so we need to pass a getter for the router to have the current state of isSmallScreenWidth. | ||
getIsSmallScreenWidth: () => isSmallScreenWidthRef.current, | ||
}); | ||
|
||
return ( | ||
<NavigationContent> | ||
<StackView | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
state={state} | ||
descriptors={descriptors} | ||
navigation={navigation} | ||
/> | ||
</NavigationContent> | ||
); | ||
} | ||
|
||
ResponsiveStackNavigator.defaultProps = defaultProps; | ||
ResponsiveStackNavigator.propTypes = propTypes; | ||
ResponsiveStackNavigator.displayName = 'ResponsiveStackNavigator'; | ||
|
||
export default createNavigatorFactory(ResponsiveStackNavigator); |