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: update header in vc below modal #1228

Merged
merged 2 commits into from
Jan 5, 2022
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 TestsExample/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import Test1204 from './src/Test1204';
import Test1209 from './src/Test1209';
import Test1214 from './src/Test1214';
import Test1227 from './src/Test1227';
import Test1228 from './src/Test1228';

enableFreeze(true);

Expand Down
6 changes: 3 additions & 3 deletions TestsExample/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ PODS:
- React-RCTVibration
- ReactCommon/turbomodule/core
- Yoga
- RNScreens (3.9.0):
- RNScreens (3.10.0):
- React-Core
- React-RCTImage
- RNVectorIcons (7.1.0):
Expand Down Expand Up @@ -592,11 +592,11 @@ SPEC CHECKSUMS:
RNCMaskedView: 5a8ec07677aa885546a0d98da336457e2bea557f
RNGestureHandler: a479ebd5ed4221a810967000735517df0d2db211
RNReanimated: b04ef2a4f0cb61b062bbcf033f84a9e470f4f60b
RNScreens: 4d79118be80f79fa1f4aa131909a1d6e86280af3
RNScreens: 03ba504f8c98607ad1f07808e71040e0afa335ec
RNVectorIcons: bc69e6a278b14842063605de32bec61f0b251a59
Yoga: c11abbf5809216c91fcd62f5571078b83d9b6720
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 2043382869260319fb066cce0337befa467ec50c

COCOAPODS: 1.10.2
COCOAPODS: 1.11.2
8 changes: 4 additions & 4 deletions TestsExample/ios/TestsExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-TestsExample/Pods-TestsExample-frameworks.sh",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/double-conversion/double-conversion.framework/double-conversion",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL/OpenSSL.framework/OpenSSL",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/Flipper-DoubleConversion/double-conversion.framework/double-conversion",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL-Universal/OpenSSL.framework/OpenSSL",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
Expand Down Expand Up @@ -495,8 +495,8 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-TestsExample-TestsExampleTests/Pods-TestsExample-TestsExampleTests-frameworks.sh",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/double-conversion/double-conversion.framework/double-conversion",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL/OpenSSL.framework/OpenSSL",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/Flipper-DoubleConversion/double-conversion.framework/double-conversion",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL-Universal/OpenSSL.framework/OpenSSL",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
Expand Down
78 changes: 78 additions & 0 deletions TestsExample/src/Test1228.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React, { useState, useEffect } from 'react';
import { Text, View, StyleSheet, Button } from 'react-native';
import {
useNavigation,
NavigationContainer,
DefaultTheme,
DarkTheme,
} from '@react-navigation/native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { createNativeStackNavigator } from 'react-native-screens/native-stack';


export const FirstScreen = () => {
const [theme, setTheme] = useState(false);
const navigation = useNavigation<any>();

useEffect(() => {
navigation.setOptions({
headerTitle: theme ? 'red' : 'green',
})
});

return (
<View style={style.container}>
<Text>Screen 1</Text>
<Button title="set theme" onPress={() => setTheme(!theme)} />
<Button title="open" onPress={() => navigation.navigate('screen2')} />
</View>
);
};

export const SecondScreen = () => {
const [theme, setTheme] = useState(false);
const navigation = useNavigation<any>();

useEffect(() => {
navigation.setOptions({
headerTitle: theme ? 'red' : 'green',
})
});

return (
<View style={style.container}>
<Text>Screen 2</Text>
<Button title="set theme" onPress={() => setTheme(!theme)} />
<Button title="close" onPress={() => navigation.goBack()} />
</View>
);
};

const Stack = createNativeStackNavigator();

export default function App() {
const [theme, setTheme] = useState(false);

setTimeout(() => setTheme(!theme), 5000);

return (
<SafeAreaProvider>
<NavigationContainer
theme={theme ? DarkTheme : DefaultTheme}
>
<Stack.Navigator screenOptions={{ stackPresentation: 'modal' }}>
<Stack.Screen name="screen1" component={FirstScreen} />
<Stack.Screen name="screen2" component={SecondScreen} options={{headerShown: false}}/>
</Stack.Navigator>
</NavigationContainer>
</SafeAreaProvider>
);
}

const style = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
5 changes: 4 additions & 1 deletion ios/RNSScreenStackHeaderConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ - (void)updateViewControllerIfNeeded
nextVC = nav.topViewController;
}

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

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
if (vc != nil && (nextVC == vc || isInFullScreenModal)) {
if (vc != nil && (nextVC == vc || isInFullScreenModal || isPresentingVC)) {
[RNSScreenStackHeaderConfig updateViewController:self.screenView.controller withConfig:self animated:YES];
}
}
Expand Down