Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import {useNavigationBuilder, createNavigatorFactory} from '@react-navigation/native';
import {StackView} from '@react-navigation/stack';
import CustomRouter from './CustomRouter';
import useWindowDimensions from '../../../../hooks/useWindowDimensions';

const propTypes = {
/* Determines if the navigator should render the StackView (narrow) or ThreePaneView (wide) */
Expand All @@ -25,17 +26,20 @@ const defaultProps = {
};

function ResponsiveStackNavigator(props) {
const isSmallScreenWidthRef = useRef(props.isSmallScreenWidth);
const {isSmallScreenWidth} = useWindowDimensions();

const isSmallScreenWidthRef = useRef(isSmallScreenWidth);

isSmallScreenWidthRef.current = isSmallScreenWidth;

Comment on lines +29 to +34

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution was not effective and the same issue occurred again. #31503

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,
});

// 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.
isSmallScreenWidthRef.current = props.isSmallScreenWidth;

return (
<NavigationContent>
<StackView
Expand Down