Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Modal's
onDismiss
work on Fabric. (#42601)
Summary: Pull Request resolved: #42601 After S390064, the OnDismiss event for Modal from D52445670 was reverted. The diff was too big and caused the SEV, so we are trying to reimplement it gradually to make sure we don't brake anything. The most important thing for our short term goal is to make the `OnDismiss` work only for iOS (following the official docs, Android never supported it) for Fabric (Bridge and Bridgeless). We also want to minimize the changes t the JS infrastructure, so we are trying not to alter the JS APIs. ## The Problem: The reason why the onDismiss event does not work is because, as soon as the `visible` property is turned to `false`, the component is removed by the React tree. When this happens, Fabric deallocate the ShadowNode and the EventEmitter. Therefore, the event is not fired. ## The Solution: We made this work by "delaying" when the component need to be removed from the reacat Tree. Rather then rendering or node or not based on the `visible` props, we are introducing a `State` object that keeps track when the Modal is rendered or not. The `state.isRendering` property is set to `true` when the `visible` prop is set to `true`. For iOS, when `visible` prop is set to `false`, instead, we wait for the Native side to actually dismiss the View and to invoke the event. When the event is fired, we manually set the `state.isRendering` property to false and the Modal can be considered dismissed. Notice that this makes also useless to have the Modal Native's snapshot to simulate that the modal is still presented. ## Changelog: [iOS][Fixed] - `onDismiss` now work on iOS with Fabric, in both Bridge and Bridgeless mode. Reviewed By: sammy-SC Differential Revision: D52959996 fbshipit-source-id: 365ca1d0234e3742df9db87007523d1a4a86079f
- Loading branch information