首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React导航5标题选项

React导航5标题选项
EN

Stack Overflow用户
提问于 2020-11-22 04:06:35
回答 1查看 148关注 0票数 0

如何在上设置Header right属性?我用screenOptions试过了,但它不能在标题的右边呈现headerRight内容。我可以在父导航组件上设置它,该组件呈现这个自定义组件,但在那里我无法访问导航属性。有谁能帮帮我吗?谢谢

代码语言:javascript
复制
<NavigationContainer>
    <Stack.Navigator>
        <Stack.Screen options={options3} name="SellerStackNavigator" 
        component={SellerStackNavigator} />
    </Stack.Navigator>
</NavigationContainer>

const SellerStack = createStackNavigator();

const SellerStackNavigator = ({ navigation, route }) => {
  <SellerStack.Navigator
        screenOptions={({ route, navigation }) => ({
          headerRight: () => (
                <View style={{
                    flexDirection: 'row',
                    marginRight: 10,
                }}>
                    <TouchableOpacity style={{
                        backgroundColor: '#fff',
                        borderRadius: 20,
                        marginRight: 10,
                        marginTop: 10,
                        height: 40,
                        width: 40,
                        alignItems: 'center',
                        justifyContent: 'center',
                        elevation: 2,
                        paddingLeft: 10,
                    }}>
                        <Image style={{
                            resizeMode: 'contain',
                            alignSelf: 'center',
                            borderWidth: 1,
                            marginRight: 10,
                            tintColor: '#000',
                            width: 15,
                            height: 18,
                        }} source={Images.searchImage}/>
                    </TouchableOpacity>
                </View>
            )
        })}>
        .
        .
        .
        .
        .
        
  </SellerStack.Navigator>
}

EN

回答 1

Stack Overflow用户

发布于 2020-11-22 05:01:52

我或多或少使用了你的代码,并且正在为我工作,所以如果你可以做一个expo,我可以检查到底发生了什么,因为你可以从任何地方用useNavigation https://snack.expo.io/@anthowm/headerright访问你的导航

代码语言:javascript
复制
function MyBackButton() {
  const navigation = useNavigation();

  return (
    <Button
      title="Back"
      onPress={() => {
        navigation.goBack();
      }}
    />
  );
}

您可以对其进行访问

代码语言:javascript
复制
<NavigationContainer>
    {(route, navigation) => {

return <Stack.Navigator>
        <Stack.Screen options={options3} name="SellerStackNavigator" 
        component={SellerStackNavigator} />
    </Stack.Navigator>}}
</NavigationContainer>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64947545

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档