12
12
13
13
const AppContainer = require ( '../ReactNative/AppContainer' ) ;
14
14
const I18nManager = require ( '../ReactNative/I18nManager' ) ;
15
- const PropTypes = require ( 'prop-types' ) ;
15
+ const NativeEventEmitter = require ( '../EventEmitter/NativeEventEmitter' ) ;
16
+ import NativeModalManager from './NativeModalManager' ;
17
+ const Platform = require ( '../Utilities/Platform' ) ;
16
18
const React = require ( 'react' ) ;
19
+ const PropTypes = require ( 'prop-types' ) ;
17
20
const ScrollView = require ( '../Components/ScrollView/ScrollView' ) ;
18
21
const StyleSheet = require ( '../StyleSheet/StyleSheet' ) ;
19
22
const View = require ( '../Components/View/View' ) ;
@@ -23,6 +26,12 @@ import type {DirectEventHandler} from '../Types/CodegenTypes';
23
26
import type { SyntheticEvent } from '../Types/CoreEventTypes' ;
24
27
import type EmitterSubscription from '../vendor/emitter/EmitterSubscription' ;
25
28
import RCTModalHostView from './RCTModalHostViewNativeComponent' ;
29
+
30
+ const ModalEventEmitter =
31
+ Platform . OS === 'ios' && NativeModalManager != null
32
+ ? new NativeEventEmitter ( NativeModalManager )
33
+ : null ;
34
+
26
35
/**
27
36
* The Modal component is a simple way to present content above an enclosing view.
28
37
*
@@ -174,9 +183,22 @@ class Modal extends React.Component<Props> {
174
183
} ;
175
184
}
176
185
186
+ componentDidMount ( ) {
187
+ if ( ModalEventEmitter ) {
188
+ this . _eventSubscription = ModalEventEmitter . addListener (
189
+ 'modalDismissed' ,
190
+ event => {
191
+ if ( event . modalID === this . _identifier && this . props . onDismiss ) {
192
+ this . props . onDismiss ( ) ;
193
+ }
194
+ } ,
195
+ ) ;
196
+ }
197
+ }
198
+
177
199
componentWillUnmount ( ) {
178
- if ( this . props . onDismiss != null ) {
179
- this . props . onDismiss ( ) ;
200
+ if ( this . _eventSubscription ) {
201
+ this . _eventSubscription . remove ( ) ;
180
202
}
181
203
}
182
204
0 commit comments