[英]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.