将参数从Child Tab-Navigator屏幕传递到父stack-navigator屏幕|反应本机导航

发布于 2025-02-11 01:15:38 字数 601 浏览 1 评论 0原文

我有嵌套导航器的问题: 我想将参数从(子导航器) tab-navigator 屏幕传递给(父导符) stack-navigator 带有反应导航 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** >

我不知道是否有一个内置的方式可以通过反应进行操作,尽管我确实搜索了一点,并且在文档中什么也没有发现,所以如果有任何有用的见解,我会是非常感谢。

I have this problem with nested navigators:
I want to pass params from a (child navigator) tab-navigator screen to a (parent navigator)
stack-navigator screen with react navigation v6.

my navigation structure looks like this:

< 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** >

I don't know if there is a built in way to do it with react-navigation, although I did search a bit and found nothing in the docs so if there is any helpful insights, I would be very thankful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃兔兔 2025-02-18 01:15:38

您可以使全球状态通过儿童组成部分。
并确保将组件加载到屏幕上
&lt; stack.screen&gt;
/ *您的组件并按照下面说明的 */

&lt;/stact.screen&gt;

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

You can make a global state to pass outside of the Child component
and make sure that loading of component to screen is inside
<Stack.Screen>
/* your component and spread the props as stated below */

</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** >

and on your child

const Child = ({setGlobal}) => {
    return <Button  onPress={()=> { setGlobal('newValue') }} />
}
export default Child
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文