简体   繁体   English

如何使用反应原生导航 v2 多次打开具有不同内容的同一个屏幕?

[英]How do i open the same screen multiple times with different content using react native navigation v2?

The objective is to reuse the same screen ui with different content and still be able to handle back navigation(like how reddit app can show multiple user/feed screens as you click on them but still handle custom back navigation) using react native navigation v2?目标是重用具有不同内容的相同屏幕 ui,并且仍然能够使用 react native navigation v2 处理后退导航(例如 reddit 应用程序如何在您单击它们时显示多个用户/提要屏幕但仍处理自定义后退导航)?

trying to use dynamic screen id's and use them in state variables.尝试使用动态屏幕 ID 并在 state 变量中使用它们。 I haven't come very far with this approach.这种方法我还没有走得很远。

The inbuilt back button handles back navigation but consider the scenario as follows:内置的后退按钮处理后退导航,但考虑如下场景:

I am working on a form and I open another form, work on it, save it and have to return to the existing form.我正在处理一个表格,然后我打开另一个表格,处理它,保存它,然后必须返回到现有表格。 custom handlers do not allow it.自定义处理程序不允许这样做。

CODE:代码:

HomeScreen:主屏幕:

Navigation.push(this.props.componentId, {
  component: {
    name: 'example.formScreen',
    passProps: {
      data: some props
    },
    options: {
      topBar: {
        title: {
          text: 'form Screen'
        }
      }
    }
  }
});

in form screen:在表单屏幕中:

<View>
<Button 
title="save form"
onpress = ()=>{
Navigation.push(this.props.componentId, {
      component: {
        name: 'example.formScreen',
        passProps: {
          data: some other props
        },
        options: {
          topBar: {
            title: {
              text: 'form Screen'
            }
          }
        }
      }
    });
}/>
<Button
title="go back"
onPress={()=>Navigation.pop(this.props.componentID)}
/>
</View>

You can push instead of navigating to the screen in this way you can use same component with different data and can use the same screen.您可以通过这种方式推送而不是导航到屏幕,您可以使用具有不同数据的相同组件并且可以使用相同的屏幕。 You have to pass params along with navigation route while navigating to the screen and these params will have the data that will help to fill the container on the new screen.在导航到屏幕时,您必须将参数与导航路线一起传递,这些参数将包含有助于在新屏幕上填充容器的数据。 The above Example is used when we are using react-navigation but in this example, I will explain about both(react-native-navigation, react-navigation) to pass params and the back button functionality will be the same as you can pop the previous route will navigating back.上面的例子是在我们使用 react-navigation 时使用的,但是在这个例子中,我将解释两者(react-native-navigation,react-navigation)来传递参数,并且后退按钮的功能将与您可以弹出上一个路由相同将导航回来。

react-native-navigation

Navigation.push(this.props.componentId, {
  component: {
    name: "ShowAnotherScreen",
    passProps: {
     data: item
    }
  }
})

react-navigation

this.props.navigation.push('YourScreenName', { YourParams })

If you want to go to the same screen and pass on the parameters, try rendering the current screen again on the current screen.如果要将go 到同屏并传递参数,请尝试在当前屏幕上再次渲染当前屏幕。

this.props.navigation.push('currentscreen',{param: "params"})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过Navigation.setRoot将导航器prop从react-native-navigation v2传递到我的初始屏幕 - How can I pass the navigator prop from react-native-navigation v2 to my splash screen via Navigation.setRoot 如何在我的Windows上从克隆的repo运行React-Native-Navigation v2 Playground? - How do I run React-Native-Navigation v2 Playground from the cloned repo on my Windows? 如何使用react-native-navigation v2添加react-native-splash-screen - How to add react-native-splash-screen with react-native-navigation v2 react native导航V2未显示屏幕标题 - react native react-navigation V2 Not showing Screen header wix 反应原生导航 v2 | 如何从侧抽屉组件将新屏幕推送到当前屏幕 - wix react native navigation v2 | how to push new screen to current screen from side drawer component 从堆栈react-native-navigation V2弹出第二个屏幕后,如何刷新第一个屏幕? - How to refresh the first screen after poping the second screen from stack react-native-navigation V2? React Native Navigation v2 sideMenu无法导航到屏幕 - React Native Navigation v2 sideMenu not able to navigate to screen wix 反应原生导航 v2 | 无法禁用打开手势 - wix react native navigation v2 | unable to disable open gestures 如何使用 react native reanimated v2 为多个条目设置动画? - How to animate multiple entries using react native reanimated v2? 在wix react native navigation V2中如何将数据从一个屏幕传递到另一个 - In wix react native navigation V2 How to pass data from one screen to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM