Skip to content

Conversation

@kmichalikk
Copy link
Contributor

Description

This fix handles the case where the whole nested ScreenStack is moved to window with UIPageViewController. The logic worked under the assumption that the nested stack is put inside outer stack's screen, but this is not the case here.

We had a similar case when the hierarchy changed on JS reload. The same fix can be used here by just removing a condition.

Changes

Modified RNSScreenStack.didMoveToWindow

Test code and steps to reproduce

Install react-native-pager-view and paste the following code into App.tsx:

import React, { useState } from 'react';
import PagerView from 'react-native-pager-view';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { Button, ScrollView, Text, View } from 'react-native';
import { NavigationContainer, NavigationIndependentTree, NavigationProp } from '@react-navigation/native';

const OuterStack = createNativeStackNavigator();
const InnerStack = createNativeStackNavigator();

function Screen(props: { navigation: NavigationProp<any> }) {
  const [click, setClick] = useState(false);

  return (<>
    <Button title='click' onPress={() => setClick(c => !c)}/>
    <Button title='push' onPress={() => props.navigation.navigate('inner2')}/>
    { click && <Text>clicked</Text>}
  </>)
}

function Inner() {
    return (<NavigationIndependentTree>
      <PagerView style={{ flex: 1 }} initialPage={0} scrollEnabled={true}>
        <View key="0" style={{ backgroundColor: 'blue' }}>
          <Text>This Works</Text>
        </View>
        <View key="1" style={{ backgroundColor: 'red' }}>
          <NavigationContainer>
              <InnerStack.Navigator>
                <InnerStack.Screen name='inner' component={Screen} options={{ headerBackButtonDisplayMode: 'minimal' }} />
                <InnerStack.Screen name='inner2' component={Screen} options={{ headerBackButtonDisplayMode: 'minimal' }} />
              </InnerStack.Navigator>
          </NavigationContainer>
        </View>
        <View key="2" style={{ backgroundColor: 'red' }}>
          <NavigationContainer>
              <InnerStack.Navigator>
                <InnerStack.Screen name='inner' component={Screen} />
                <InnerStack.Screen name='inner2' component={Screen} />
              </InnerStack.Navigator>
          </NavigationContainer>
        </View>
      </PagerView>
    </NavigationIndependentTree>)
}

export default function App() {
  return (
    <NavigationContainer>
      <OuterStack.Navigator>
        <OuterStack.Screen name='outer' component={Inner} />
      </OuterStack.Navigator>
    </NavigationContainer>
  )
}

@kmichalikk kmichalikk marked this pull request as draft December 10, 2025 14:25
@kmichalikk kmichalikk self-assigned this Dec 10, 2025
@kmichalikk kmichalikk added Type: Bug Something isn't working Area: Native Stack Platform: iOS This issue is specific to iOS labels Dec 10, 2025
@kkafar
Copy link
Member

kkafar commented Dec 16, 2025

What is the state of this PR here? Is it ready for review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Native Stack Platform: iOS This issue is specific to iOS Type: Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants