Skip to content

Commit

Permalink
fix: 31503
Browse files Browse the repository at this point in the history
  • Loading branch information
tienifr committed Dec 4, 2023
1 parent cc4add5 commit 1578aa5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {StackRouter} from '@react-navigation/native';
import lodashFindLast from 'lodash/findLast';
import _ from 'underscore';
import getIsSmallScreenWidth from '@libs/getIsSmallScreenWidth';
import NAVIGATORS from '@src/NAVIGATORS';
import SCREENS from '@src/SCREENS';

Expand Down Expand Up @@ -68,8 +69,9 @@ function CustomRouter(options) {
return {
...stackRouter,
getRehydratedState(partialState, {routeNames, routeParamList}) {
const isSmallScreenWidth = getIsSmallScreenWidth();
// Make sure that there is at least one CentralPaneNavigator (ReportScreen by default) in the state if this is a wide layout
if (!isAtLeastOneCentralPaneNavigatorInState(partialState) && !options.getIsSmallScreenWidth()) {
if (!isAtLeastOneCentralPaneNavigatorInState(partialState) && !isSmallScreenWidth) {
// If we added a route we need to make sure that the state.stale is true to generate new key for this route
// eslint-disable-next-line no-param-reassign
partialState.stale = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ function ResponsiveStackNavigator(props) {
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,
});

const stateToRender = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ function ResponsiveStackNavigator(props) {
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 (
Expand Down
6 changes: 6 additions & 0 deletions src/libs/getIsSmallScreenWidth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {Dimensions} from 'react-native';
import variables from '@styles/variables';

export default function getIsSmallScreenWidth(windowWidth = Dimensions.get('window').width) {
return windowWidth <= variables.mobileResponsiveWidthBreakpoint;
}

0 comments on commit 1578aa5

Please sign in to comment.