gpt4 book ai didi

javascript - React Native 导航子级父级

转载 作者:太空宇宙 更新时间:2023-11-04 01:20:50 26 4
gpt4 key购买 nike

我一直在尝试制作导航组件,但遇到错误。

这是我的 StackNavigation View 的架构:

const App = createStackNavigator({
Register:{
screen:Registration,
},
Home: {
screen: SwipeNavigator({

Home: {
screen: Record,
left: 'QRcode',
right: 'Conv',
top: 'Profil',

},

QRcode: {
screen: QRcode,
type:'push'
},

Conv: {
screen: Conversation,
type:'push'
},
Profil: {
screen: Profil,
type:'push'
},



}),
navigationOptions: {
header: null,
},
}
});

不幸的是,当我在 SwipeNavigator 中时,我无法去注册。我收到一条错误消息,指示 this.props.navigation 未定义。

有谁知道我为什么会遇到此错误以及如何解决它?

提前感谢您的回复

最佳答案

我有一个很好的解决方案可以帮助您解决所有 this.props.navigation 问题:) 我刚刚从另一个问题中复制/粘贴了我之前的答案。它解释了如何使用它以及如何使用新的 React Navigation Helper 来做到这一点。如果您对此有任何疑问,我随时为您提供帮助。它只会解决您的整个导航问题。

I have created a library for handling navigation problem and also prevent the usage of this.props.navigation prop.

React Navigation Helpers

Usage is very simple. On your App.js or your navigator simply set the global level navigator.

import NavigationService from "react-navigation-helpers";


<MainNavigator
ref={navigatorRef =>
NavigationService.setGlobalLevelNavigator(navigatorRef)
}
/>

Then you use ANYWHERE on your project with this simple code segment:

NavigationService.navigate("home")

Of course, you still need to import the NavigationService :)

You can find a more detailed document on the library's README. If you still have a question, feel free to ask, I will help you gladly.

关于javascript - React Native 导航子级父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59345984/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com