[英]How can I go back on Stack Navigation in React Navigation?
I created a navigation called UpdatePlace in createStackNavigator我在 createStackNavigator 中创建了一个名为 UpdatePlace 的导航
By default, when the headerback icon is clicked, navigation goes back to the previous component.默认情况下,当单击 headerback 图标时,导航会返回到上一个组件。
However, when I press the button after applying my own custom HeaderLeft icon with headerLeft, it does not go back.但是,当我在使用 headerLeft 应用我自己的自定义 HeaderLeft 图标后按下按钮时,它不会返回 go。 What should I do at this time?
这个时候我该怎么办?
this is my code这是我的代码
const RootStack = createStackNavigator();
<RootStack.Navigator screenOptions={{ headerShown: false }}>
<RootStack.Screen name="UpdatePlace" component={UpdatePlace}
options={{
headerShown: true,
headerTitle: "Hello",
headerTitleAlign: 'center',
headerLeft: () => (
<Pressable style={{ width: '100%', height: '80%' }}>
<Image source={cusImage.Arrow} style={{ width: '40%', height: '70%', resizeMode: 'contain' }}
/>
</Pressable>
),
}}
/>
</RootStack.Navigator>
You also need to add the click action to your custom element您还需要将点击操作添加到您的自定义元素
headerLeft: ({ navigation }) => (
<Pressable onPress={() => navigation.goBack()} style={{ width: '100%', height: '80%' }}>
<Image source={cusImage.Arrow} style={{ width: '40%', height: '70%', resizeMode: 'contain' }} />
</Pressable>
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.