Skip to content

Commit c5b8705

Browse files
committed
Add reproduction for 2714
1 parent 3e30ca3 commit c5b8705

2 files changed

Lines changed: 167 additions & 0 deletions

File tree

apps/src/tests/Test2714.tsx

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import React from 'react';
2+
// import { NavigationContainer } from '@react-navigation/native';
3+
// import { Pressable, Text, View, StyleSheet, Button } from 'react-native';
4+
// import { createNativeStackNavigator } from '@react-navigation/native-stack';
5+
// import { GestureHandlerRootView } from 'react-native-gesture-handler';
6+
//
7+
// const styles = StyleSheet.create({
8+
// button: {
9+
// width: 42,
10+
// height: 42,
11+
// marginHorizontal: 5,
12+
// padding: 5,
13+
// borderRadius: 20,
14+
// justifyContent: 'center',
15+
// alignItems: 'center',
16+
// backgroundColor: 'blue',
17+
// },
18+
// buttonsView: {
19+
// flexDirection: 'row',
20+
// borderWidth: 1,
21+
// },
22+
// });
23+
//
24+
// const Stack = createNativeStackNavigator();
25+
//
26+
// function MyStack() {
27+
// return (
28+
// <Stack.Navigator
29+
// screenOptions={{
30+
// headerShown: true,
31+
// headerBackButtonDisplayMode: 'minimal',
32+
// }}>
33+
// <Stack.Screen name="Home" component={HomeScreen} />
34+
// <Stack.Screen name="Profile" component={HomeScreen} />
35+
// </Stack.Navigator>
36+
// );
37+
// }
38+
//
39+
// const HomeScreen = ({ navigation }: any) => {
40+
// const [secondButtonShown, setSecondButtonShown] = React.useState(true);
41+
// const [thirdButtonShown, setThirdButtonShown] = React.useState(true);
42+
// const [showAllButtons, setShowAllButtons] = React.useState(true);
43+
//
44+
// const headerRight = React.useCallback(() => {
45+
// return (
46+
// <>
47+
// <Pressable style={styles.button} onPress={() => console.log(1)}>
48+
// <Text>1</Text>
49+
// </Pressable>
50+
// {secondButtonShown && (
51+
// <Pressable style={styles.button} onPress={() => console.log(2)}>
52+
// <Text>2</Text>
53+
// </Pressable>
54+
// )}
55+
// {thirdButtonShown && (
56+
// <Pressable style={styles.button} onPress={() => console.log(3)}>
57+
// <Text>3</Text>
58+
// </Pressable>
59+
// )}
60+
// </>
61+
// );
62+
// }, [secondButtonShown, thirdButtonShown]);
63+
//
64+
// React.useLayoutEffect(() => {
65+
// navigation.setOptions({
66+
// headerStyle: { backgroundColor: 'pink' },
67+
// headerRight: () => (
68+
// <View
69+
// style={[styles.buttonsView, !showAllButtons && { display: 'none' }]}>
70+
// {headerRight()}
71+
// <Pressable style={styles.button} onPress={() => console.log('D')}>
72+
// <Text>[D]</Text>
73+
// </Pressable>
74+
// </View>
75+
// ),
76+
// });
77+
// }, [navigation, headerRight, showAllButtons]);
78+
//
79+
// return (
80+
// <View>
81+
// <Text>Home Screen</Text>
82+
// <Button
83+
// title="Toggle 2nd button"
84+
// onPress={() => setSecondButtonShown(p => !p)}
85+
// />
86+
// <Button
87+
// title="Toggle 3rd button"
88+
// onPress={() => setThirdButtonShown(p => !p)}
89+
// />
90+
// <Button
91+
// title="Toggle All Right Buttons"
92+
// onPress={() => setShowAllButtons(p => !p)}
93+
// />
94+
// </View>
95+
// );
96+
// };
97+
//
98+
// function App() {
99+
// return (
100+
// <GestureHandlerRootView>
101+
// <NavigationContainer>
102+
// <MyStack />
103+
// </NavigationContainer>
104+
// </GestureHandlerRootView>
105+
// );
106+
// }
107+
//
108+
// export default App;
109+
110+
import {
111+
createStaticNavigation,
112+
useNavigation,
113+
} from '@react-navigation/native';
114+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
115+
import { Button, StyleSheet, Text, View } from 'react-native';
116+
import { SafeAreaProvider } from 'react-native-safe-area-context';
117+
import { useEffect } from 'react';
118+
119+
const RootStack = createNativeStackNavigator({
120+
screens: {
121+
Home: {
122+
screen: HomeScreen,
123+
options: {
124+
headerRight: () => <Text style={styles.headerRight}>Hi</Text>,
125+
headerTitle: 'Longer Screen Title',
126+
},
127+
},
128+
},
129+
});
130+
131+
const RootNavigation = createStaticNavigation(RootStack);
132+
133+
export default function App() {
134+
return (
135+
<SafeAreaProvider>
136+
<RootNavigation />
137+
</SafeAreaProvider>
138+
);
139+
}
140+
141+
function HomeScreen() {
142+
const navigation = useNavigation();
143+
144+
return (
145+
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
146+
<Button
147+
title={'Update Header'}
148+
onPress={() => {
149+
navigation.setOptions({
150+
headerRight: () => (
151+
<Text style={[styles.headerRight]}>Longer Header Right</Text>
152+
),
153+
});
154+
}}
155+
/>
156+
</View>
157+
);
158+
}
159+
160+
const styles = StyleSheet.create({
161+
headerRight: {
162+
paddingHorizontal: 10,
163+
fontSize: 20,
164+
fontWeight: 'bold',
165+
},
166+
});

apps/src/tests/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export { default as Test2611 } from './Test2611';
124124
export { default as Test2631 } from './Test2631';
125125
export { default as Test2668 } from './Test2668';
126126
export { default as Test2675 } from './Test2675';
127+
export { default as Test2714 } from './Test2714';
127128
export { default as Test2717 } from './Test2717';
128129
export { default as Test2767 } from './Test2767';
129130
export { default as Test2789 } from './Test2789';

0 commit comments

Comments
 (0)