简体   繁体   中英

RN callback when a Modal has been dismissed for iOS

I'm using the React Native component Modal in my application. I would need a callback when the modal has been dismissed (like the native iOS completion block/closure). 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. 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.

As of React-Native 0.45 there is no call back property on Modal component to hear when it is closed.

BTW Modal component is a controlled one, controlled by the visible property

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

you can use this state variable to update changes when modalVisible=false, that is when Modal is getting closed.

You can also approximately calculate the Modal exit animation time and use a Timeout function after modalVisible becomes false to bring any changes.

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).

Check React-Native Modal Docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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