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 bug with header hide prop on the screen under the modal #2229

Merged
merged 3 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions apps/test-examples/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import Test2069 from './src/Test2069';
import Test2118 from './src/Test2118';
import Test2184 from './src/Test2184';
import Test2223 from './src/Test2223';
import Test2229 from './src/Test2229';
import TestScreenAnimation from './src/TestScreenAnimation';
import TestHeader from './src/TestHeader';

Expand Down
136 changes: 136 additions & 0 deletions apps/test-examples/src/Test2229.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import React, { useCallback, useEffect, useState } from 'react';
import {
ScrollView,
StyleSheet,
useColorScheme,
View,
AppState,
AppStateStatus,
Button,
} from 'react-native';
import {
DarkTheme,
DefaultTheme,
NavigationContainer,
ParamListBase,
} from '@react-navigation/native';
import {
NativeStackNavigationProp,
createNativeStackNavigator,
} from '@react-navigation/native-stack';
import { enableFreeze } from 'react-native-screens';

const Stack = createNativeStackNavigator();

let lastState: AppStateStatus;

export default function App() {
const [counter, setCounter] = useState(0);
const handleChange = useCallback((nextState: AppStateStatus) => {
if (nextState === 'active' && lastState === 'background') {
setCounter(c => c + 1);
}
lastState = nextState;
}, []);

useEffect(() => {
enableFreeze(false);
const listener = AppState.addEventListener('change', handleChange);
handleChange(AppState.currentState);
return () => {
listener.remove();
};
}, [handleChange]);

const theme = useColorScheme();

return (
<NavigationContainer theme={theme === 'light' ? DefaultTheme : DarkTheme}>
<Stack.Navigator>
<Stack.Screen
name="Push"
component={PushScreen}
options={{
presentation: 'card',
title: `header ${counter}`,
}}
/>
<Stack.Screen
name="PushWithoutHeader"
component={PushScreen}
options={{
presentation: 'card',
headerShown: false,
title: 'no header',
}}
/>
<Stack.Screen
name="Modal"
component={ModalScreen}
options={{
presentation: 'modal',
orientation: 'portrait_up',
title: 'modal',
headerShown: false,
}}
/>
</Stack.Navigator>
</NavigationContainer>
);
}

interface ModalScreenProps {
navigation: NativeStackNavigationProp<ParamListBase>;
}

function ModalScreen({ navigation }: ModalScreenProps) {
return (
<View style={styles.container}>
<Button
testID="stack-presentation-modal-screen-go-back-button"
title="Go back"
onPress={navigation.goBack}
/>
</View>
);
}

interface PushScreenProps {
navigation: NativeStackNavigationProp<ParamListBase>;
}

function PushScreen({ navigation }: PushScreenProps) {
return (
<ScrollView contentContainerStyle={styles.container}>
<Button
testID="stack-presentation-screen-with-header"
title="Push"
onPress={() => navigation.push('Push')}
/>
<Button
testID="stack-presentation-form-screen-push-modal"
title="Open modal"
onPress={() => navigation.push('Modal')}
/>
<Button
testID="stack-presentation-screen-without-header"
title="Push without header"
onPress={() => navigation.push('PushWithoutHeader')}
/>
{navigation.canGoBack() && (
<Button
testID="stack-presentation-screen-go-back-button"
title="Go back"
onPress={navigation.goBack}
/>
)}
</ScrollView>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 10,
},
});
4 changes: 2 additions & 2 deletions ios/RNSScreenStackHeaderConfig.mm
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ - (void)updateViewControllerIfNeeded
nextVC = nav.topViewController;
}

// we want updates sent to the VC below modal too since it is also visible
BOOL isPresentingVC = nextVC != nil && vc.presentedViewController == nextVC;
// we want updates sent to the VC directly below modal too since it is also visible
BOOL isPresentingVC = nextVC != nil && vc.presentedViewController == nextVC && vc == nav.topViewController;

BOOL isInFullScreenModal = nav == nil && _screenView.stackPresentation == RNSScreenStackPresentationFullScreenModal;
// if nav is nil, it means we can be in a fullScreen modal, so there is no nextVC, but we still want to update
Expand Down
Loading