Skip to content

Commit 29d3c2c

Browse files
alduzykkafar
authored andcommitted
fix(iOS): right header incorrect position (#2316)
## Description This PR fixes the incorrect position of the custom header items when updating more than one option at the same time. The proposed solution let us remove the previous fix for a similar problem: #2248 which only fixed the issue on fabric. Fixes #432, #2231. ## Changes - forced re-layout of the navigation controller when subviews are updated - removed previous fix - updated `Test432` repro <!-- ## Screenshots / GIFs Here you can add screenshots / GIFs documenting your change. You can add before / after section if you're changing some behavior. ### Before ### After --> ## Test code and steps to reproduce - use `Test432` and `Test2231` to test this fix on both architectures. ## Checklist - [x] Included code example that can be used to test this change - [x] Ensured that CI passes (cherry picked from commit bc95fa4)
1 parent 746eff8 commit 29d3c2c

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

apps/src/tests/Test432.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,34 @@ type RootStackParamList = {
1313
};
1414
type RootStackScreenProps<T extends keyof RootStackParamList> =
1515
NativeStackScreenProps<RootStackParamList, T>;
16+
1617
const HomeScreen = ({ navigation }: RootStackScreenProps<'Home'>) => {
17-
const showSettings = useCallback(() => {
18-
navigation.navigate('Settings');
19-
}, [navigation]);
18+
const [x, setX] = React.useState(false);
19+
React.useEffect(() => {
20+
navigation.setOptions({
21+
headerBackVisible: !x,
22+
headerRight: x
23+
? () => (
24+
<View style={{ backgroundColor: 'green', width: 20, height: 20 }} />
25+
)
26+
: () => (
27+
<View style={{ backgroundColor: 'green', width: 10, height: 10 }} />
28+
),
29+
});
30+
}, [navigation, x]);
31+
2032
return (
2133
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
22-
<Button onPress={showSettings} title={'Show settings'} />
34+
<Button title="Tap me for header update" onPress={() => setX(!x)} />
35+
<Button
36+
title={'Show settings'}
37+
onPress={() => navigation.navigate('Settings')}
38+
/>
2339
</View>
2440
);
2541
};
2642

27-
const SettingsScreen = ({ navigation }: RootStackScreenProps<'Settings'>) => {
43+
const SettingsScreen = () => {
2844
return (
2945
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
3046
<Text>Settings</Text>
@@ -47,7 +63,7 @@ const RootNavigator = () => {
4763
[navigation],
4864
);
4965
return (
50-
<RootStack.Navigator screenOptions={{ headerShown: false }}>
66+
<RootStack.Navigator>
5167
<RootStack.Screen name="Home" component={HomeScreen} />
5268
<RootStack.Screen
5369
name="Settings"

ios/RNSScreenStackHeaderConfig.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,9 @@ + (void)updateViewController:(UIViewController *)vc
681681
break;
682682
}
683683
}
684+
// We're forcing a re-layout when the subviews change,
685+
// see: https://github.com/software-mansion/react-native-screens/pull/2316
686+
[navctr.view layoutIfNeeded];
684687
}
685688

686689
// This assignment should be done after `navitem.titleView = ...` assignment (iOS 16.0 bug).

ios/RNSScreenStackHeaderSubview.mm

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ - (void)updateLayoutMetrics:(const react::LayoutMetrics &)layoutMetrics
7878
self);
7979
} else {
8080
self.bounds = CGRect{CGPointZero, frame.size};
81-
// We're forcing the parent view to layout this subview with correct frame size,
82-
// see: https://github.com/software-mansion/react-native-screens/pull/2248
83-
[self.superview layoutIfNeeded];
8481
}
8582
}
8683

0 commit comments

Comments
 (0)