Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iOS): non-interactive screen while switching between bottom-tab and native-stack navigators #2260

Merged
merged 12 commits into from
Jul 30, 2024
86 changes: 86 additions & 0 deletions apps/src/tests/Test2252.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { useState } from 'react';
import { Alert, Button, Text, View, Switch } from 'react-native';
import React from 'react';
import { SafeAreaProvider } from 'react-native-safe-area-context';

const RootStack = createNativeStackNavigator();
const BottomTab = createBottomTabNavigator();

function TabScreen() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button
title="Test"
onPress={() => {
Alert.alert('Test');
}}
/>
<Switch
trackColor={{ false: '#767577', true: '#81b0ff' }}
thumbColor={'#f5dd4b'}
ios_backgroundColor="#3e3e3e"
onValueChange={() => {
Alert.alert('Test');
}}
/>
</View>
);
}

function TabsScreen() {
return (
<BottomTab.Navigator initialRouteName="tab">
<BottomTab.Screen name="tab" component={TabScreen} />
</BottomTab.Navigator>
);
}

export function RootStackNavigator() {
return (
<RootStack.Navigator
initialRouteName="tabNavigation"
screenOptions={{ headerShown: false }}>
<RootStack.Screen name="tabNavigation" component={TabsScreen} />
</RootStack.Navigator>
);
}

function LoginScreen() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>No tabs</Text>
</View>
);
}

export function LoginStackNavigator() {
return (
<RootStack.Navigator
initialRouteName="login"
screenOptions={{ headerShown: false }}>
<RootStack.Screen name="login" component={LoginScreen} />
</RootStack.Navigator>
);
}

export default function App() {
const [showTabs, setShowTabs] = useState(true);
return (
<SafeAreaProvider>
<NavigationContainer key={showTabs ? 'a' : 'b'}>
{showTabs ? <RootStackNavigator /> : <LoginStackNavigator />}
</NavigationContainer>
<View style={{ marginBottom: 32 }}>
<Button
title="Toggle"
onPress={() => {
setShowTabs(!showTabs);
}}
/>
</View>
</SafeAreaProvider>
);
}
1 change: 1 addition & 0 deletions apps/src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ export { default as Test2229 } from './Test2229';
export { default as Test2231 } from './Test2231';
export { default as Test2232 } from './Test2232';
export { default as Test2235 } from './Test2235';
export { default as Test2252 } from './Test2252';
export { default as TestScreenAnimation } from './TestScreenAnimation';
export { default as TestHeader } from './TestHeader';
2 changes: 1 addition & 1 deletion ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ - (void)updateLayoutMetrics:(const react::LayoutMetrics &)layoutMetrics
_newLayoutMetrics = layoutMetrics;
_oldLayoutMetrics = oldLayoutMetrics;
UIViewController *parentVC = self.reactViewController.parentViewController;
if (parentVC != nil && ![parentVC isKindOfClass:[RNSNavigationController class]]) {
if (parentVC == nil || ![parentVC isKindOfClass:[RNSNavigationController class]]) {
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
}
// when screen is mounted under RNSNavigationController it's size is controller
Expand Down
Loading