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' ) ;
@@ -22,6 +25,12 @@ import type {ViewProps} from '../Components/View/ViewPropTypes';
22
25
import type { DirectEventHandler } from '../Types/CodegenTypes' ;
23
26
import type EmitterSubscription from '../vendor/emitter/EmitterSubscription' ;
24
27
import RCTModalHostView from './RCTModalHostViewNativeComponent' ;
28
+
29
+ const ModalEventEmitter =
30
+ Platform . OS === 'ios' && NativeModalManager != null
31
+ ? new NativeEventEmitter ( NativeModalManager )
32
+ : null ;
33
+
25
34
/**
26
35
* The Modal component is a simple way to present content above an enclosing view.
27
36
*
@@ -178,9 +187,22 @@ class Modal extends React.Component<Props> {
178
187
} ;
179
188
}
180
189
190
+ componentDidMount ( ) {
191
+ if ( ModalEventEmitter ) {
192
+ this . _eventSubscription = ModalEventEmitter . addListener (
193
+ 'modalDismissed' ,
194
+ event => {
195
+ if ( event . modalID === this . _identifier && this . props . onDismiss ) {
196
+ this . props . onDismiss ( ) ;
197
+ }
198
+ } ,
199
+ ) ;
200
+ }
201
+ }
202
+
181
203
componentWillUnmount ( ) {
182
- if ( this . props . onDismiss != null ) {
183
- this . props . onDismiss ( ) ;
204
+ if ( this . _eventSubscription ) {
205
+ this . _eventSubscription . remove ( ) ;
184
206
}
185
207
}
186
208
0 commit comments