嵌套导航器有这样的问题:我想从(子导航器)选项卡导航器传递参数屏幕到(父导航器)stack-navigator带有react导航的屏幕v6.
我的导航结构是这样的:
< STACK NAVIGATOR >: : parent navigator
< some screens here .. />
*< screen which will receive the params />
< TAB NAVIGATOR > : child navigator
< some screens here .. />
*< screen which will send params />
</ TAB NAVIGATOR** >
</ **STACK NAVIGATOR** >
我不知道是否有一个内置的方法来做反应导航,虽然我确实搜索了一下,但在文档中没有发现任何东西,所以如果有任何有用的见解,我将非常感谢。
你可以创建一个全局状态传递到子组件外部并确保组件加载到屏幕是在里面& lt; Stack.Screen>/*你的组件,并按如下所述展开props */
& lt;/Stact.Screen>
const [global,setGlobal]= useState('')
< STACK NAVIGATOR >: : parent navigator
<Stack.Screen>
{(props) => <Parent global={global} {...props} />}
</Stack.Screen>
*< screen which will receive the params />
< TAB NAVIGATOR > : child navigator
/// put your component here.....
<Tab.Screen name='Name'>
{(props) => <Child setGlobal={setGlobal} {...props} />}
<Tab.Screen>
*< screen which will send params />
</ TAB NAVIGATOR** >
</ **STACK NAVIGATOR** >
和你的孩子
const Child = ({setGlobal}) => {
return <Button onPress={()=> { setGlobal('newValue') }} />
}
export default Child