简体   繁体   English

取消iOS模态时的RN回调

[英]RN callback when a Modal has been dismissed for iOS

I'm using the React Native component Modal in my application. 我在应用程序中使用React Native组件Modal I would need a callback when the modal has been dismissed (like the native iOS completion block/closure). 取消模态后,我需要回调(例如本机iOS完成块/关闭)。 Looking at the documentation, I wasn't able to find anything about it, but probably I'm missing something. 在查看文档时,我找不到任何有关它的信息,但是可能我缺少了一些东西。

You should try to fire your callback on Modal componentWillUnmount and it will be fired right after the modal closes. 您应该尝试在Modal componentWillUnmount上触发您的回调,并且将在模式关闭后立即触发。 Unfortunately the modal API is not Promise based, even if it should be, so this is the only way I found to solve this problem. 不幸的是,模态API即使不是应该也不基于Promise ,所以这是我发现解决此问题的唯一方法。

As of React-Native 0.45 there is no call back property on Modal component to hear when it is closed. 从React-Native 0.45开始,Modal组件上没有回调属性可以关闭它。

BTW Modal component is a controlled one, controlled by the visible property BTW Modal组件是受控组件,受可见属性控制

visible={this.state.modalVisible} //boolean

you can use this state variable to update changes when modalVisible=false, that is when Modal is getting closed. 您可以在modalVisible = false时(也就是在Modal关闭时)使用此状态变量来更新更改。

You can also approximately calculate the Modal exit animation time and use a Timeout function after modalVisible becomes false to bring any changes. 您还可以大致计算Modal退出动画时间,并在modalVisible变为false后进行任何更改后使用Timeout函数。

Note: In android the general trend is to close the Modal on physical back button press, hence u need to also handle 'onRequestClose' property of the Modal(where you can handle your call back updates). 注意:在android中,总体趋势是在按下物理后退按钮时关闭Modal,因此您还需要处理Modal的“ onRequestClose”属性(您可以在其中处理回调更新)。

Check React-Native Modal Docs 检查React-Native模态文档

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM