将参数传递到滑动/手势上的上一个屏幕
我已经彻底阅读了有关使用React导航在屏幕之间传递参数的文档: https://reactnavigation.orgg/docs /params/
但是,所有这些示例仅在您调用导航时起作用。例如:
<Button
title="Done"
onPress={() => {
// Pass and merge params back to home screen
navigation.navigate({
name: 'Home',
params: { post: postText },
merge: true,
});
}}
/>
我有一个带有后背按钮的屏幕,我可以在其中调用navigation.navigate.navigate和通过按钮按下按钮,就像上面的示例一样。但是,用户也可以从左侧滑动以返回Android上的第一个屏幕(我也假设iOS)。
因此,我的问题是:
当用户刷新回去时,我有没有办法将相同的数据传递给上一个屏幕(而不是按下后面的按钮)?
I've thoroughly read the documentation on passing params between screens with React Navigation: https://reactnavigation.org/docs/params/
However, all of those examples only work if you are calling navigation.navigate manually and passing the params. For example:
<Button
title="Done"
onPress={() => {
// Pass and merge params back to home screen
navigation.navigate({
name: 'Home',
params: { post: postText },
merge: true,
});
}}
/>
I have a screen with a back button, where I can call navigation.navigate and pass params on button press, like in the example above. However, the user can also swipe from the left to go back to the first screen on Android (and I'm assuming iOS as well).
So, my question:
Is there a way for me to pass the same data to the previous screen when the user swipes to go back (instead of pressing the back button)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能没有一种更好的方式。但是,我们可以通过
假设您有一个屏幕
b
,您想向后滑动以转到屏幕home
,然后将params传递给home
fromb
在该滑动动作上。然后,您可以如下实现这一目标。编辑:
navigation.navigate
很明显,beforeRemove
事件再次引起无限循环。我们可以如上图所示。There might be a better way that I am unaware of. However, we can achieve this manually by preventing the default back action and handling this ourselves.
Suppose that you have a screen
B
and you want to swipe back to go to a screenHome
and pass params toHome
fromB
on that swipe action. Then, you can achieve this as follows.Edit: The
navigation.navigate
fires thebeforeRemove
event again, obviously, which causes an infinite loop. We can guard this as shown above.