覆盖反压反应本机路由器通量 [英] Override back press react native router flux

查看:34
本文介绍了覆盖反压反应本机路由器通量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的本机应用程序中使用本机路由器通量.我想覆盖后退按钮按下事件,因为我想在返回之前添加确认弹出窗口.我搜索了很多,但我找到的所有链接都是用于覆盖 Android 的硬件后退按钮.我不仅想覆盖硬件后退,还想覆盖导航栏中的后退按钮按下事件(适用于 Android 和 iOS).请帮帮我.

I am using react native router flux in my react native app. I want to override the back button press event as I want to add confirmation popup before going back. I have searched a lot but all the links I found was for overriding hardware back button press of Android. I not only want to override the hardware back press but also want to override the back button press event in the navigation bar (for both Android and iOS). Please help me out here.

我找到了一种方法,通过在我的场景 backonBack 中添加两个道具来覆盖后退事件.但现在的问题是我希望这个 backpress 是有条件的.我将一个布尔属性 edit 传递给这个场景.如果编辑为真,那么我只想覆盖 backpress 否则我只想要默认的.那么如何使用传递给该场景的道具更改我的 Router.js 中的 Scene 参数?

I found one way to override the back press event by adding two props in my scene back and onBack. But now problem is I want this backpress to be conditional. I am passing a boolean prop edit to this scene. If the edit is true then only I want to override the backpress otherwise I just want the default one. So how can I change the Scene parameter in my Router.js using the props being passed to that scene?

sudo 代码

if(edit){
   openConfirmationDialog();
} else {
   Actions.pop();
}

推荐答案

好的!我找到了通往它的路.

Alright! I found the way to it.

无论我在哪里打开这个场景,我都可以像这样传递 onBack 回调 Actions.Home({onBack: () => console.log('custom back callback') });

From wherever I am opening this scene I can pass onBack callback like this Actions.Home({onBack: () => console.log('custom back callback') });

这样我就可以在每次打开那个场景时提供动态回调.

This way I can provide dynamic back callback every time I open that scene.

这篇关于覆盖反压反应本机路由器通量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆