@@ -65,7 +65,6 @@ var ModalBox = createReactClass({
65
65
easing : PropTypes . func ,
66
66
coverScreen : PropTypes . bool ,
67
67
keyboardTopOffset : PropTypes . number ,
68
-
69
68
onClosed : PropTypes . func ,
70
69
onOpened : PropTypes . func ,
71
70
onClosingState : PropTypes . func ,
@@ -149,7 +148,7 @@ var ModalBox = createReactClass({
149
148
* The keyboard is hidden (IOS only)
150
149
*/
151
150
onKeyboardHide : function ( evt ) {
152
- this . state . keyboardOffset = 0 ;
151
+ this . setState ( { keyboardOffset : 0 } ) ;
153
152
} ,
154
153
155
154
/*
@@ -161,8 +160,9 @@ var ModalBox = createReactClass({
161
160
var keyboardFrame = evt . endCoordinates ;
162
161
var keyboardHeight = this . state . containerHeight - keyboardFrame . screenY ;
163
162
164
- this . state . keyboardOffset = keyboardHeight ;
165
- this . animateOpen ( ) ;
163
+ this . setState ( { keyboardOffset : keyboardHeight } , ( ) => {
164
+ this . animateOpen ( ) ;
165
+ } ) ;
166
166
} ,
167
167
168
168
/*
@@ -171,19 +171,21 @@ var ModalBox = createReactClass({
171
171
animateBackdropOpen : function ( ) {
172
172
if ( this . state . isAnimateBackdrop ) {
173
173
this . state . animBackdrop . stop ( ) ;
174
- this . state . isAnimateBackdrop = false ;
175
174
}
176
175
177
- this . state . isAnimateBackdrop = true ;
178
- this . state . animBackdrop = Animated . timing (
176
+ let animBackdrop = Animated . timing (
179
177
this . state . backdropOpacity ,
180
178
{
181
179
toValue : 1 ,
182
180
duration : this . props . animationDuration
183
181
}
184
182
) ;
185
- this . state . animBackdrop . start ( ( ) => {
186
- this . state . isAnimateBackdrop = false ;
183
+
184
+ this . setState ( {
185
+ isAnimateBackdrop : true ,
186
+ animBackdrop
187
+ } , ( ) => {
188
+ this . state . animBackdrop . start ( ) ;
187
189
} ) ;
188
190
} ,
189
191
@@ -193,19 +195,21 @@ var ModalBox = createReactClass({
193
195
animateBackdropClose : function ( ) {
194
196
if ( this . state . isAnimateBackdrop ) {
195
197
this . state . animBackdrop . stop ( ) ;
196
- this . state . isAnimateBackdrop = false ;
197
198
}
198
199
199
- this . state . isAnimateBackdrop = true ;
200
- this . state . animBackdrop = Animated . timing (
200
+ let animBackdrop = Animated . timing (
201
201
this . state . backdropOpacity ,
202
202
{
203
203
toValue : 0 ,
204
204
duration : this . props . animationDuration
205
205
}
206
206
) ;
207
- this . state . animBackdrop . start ( ( ) => {
208
- this . state . isAnimateBackdrop = false ;
207
+
208
+ this . setState ( {
209
+ isAnimateBackdrop : false ,
210
+ animBackdrop
211
+ } , ( ) => {
212
+ this . state . animBackdrop . start ( ) ;
209
213
} ) ;
210
214
} ,
211
215
@@ -215,7 +219,7 @@ var ModalBox = createReactClass({
215
219
stopAnimateOpen : function ( ) {
216
220
if ( this . state . isAnimateOpen ) {
217
221
if ( this . state . animOpen ) this . state . animOpen . stop ( ) ;
218
- this . state . isAnimateOpen = false ;
222
+ this . setState ( { isAnimateOpen : false } ) ;
219
223
}
220
224
} ,
221
225
@@ -229,29 +233,36 @@ var ModalBox = createReactClass({
229
233
if ( this . props . backdrop )
230
234
this . animateBackdropOpen ( ) ;
231
235
232
- this . state . isAnimateOpen = true ;
233
-
234
- requestAnimationFrame ( ( ) => {
235
- // Detecting modal position
236
- this . state . positionDest = this . calculateModalPosition ( this . state . containerHeight - this . state . keyboardOffset , this . state . containerWidth ) ;
237
- if ( this . state . keyboardOffset && ( this . state . positionDest < this . props . keyboardTopOffset ) ) {
238
- this . state . positionDest = this . props . keyboardTopOffset ;
239
- }
240
- this . state . animOpen = Animated . timing (
241
- this . state . position ,
242
- {
243
- toValue : this . state . positionDest ,
244
- duration : this . props . animationDuration ,
245
- easing : this . props . easing ,
236
+ this . setState ( {
237
+ isAnimateOpen : true ,
238
+ isOpen : true ,
239
+ } , ( ) => {
240
+ requestAnimationFrame ( ( ) => {
241
+ // Detecting modal position
242
+ let positionDest = this . calculateModalPosition ( this . state . containerHeight - this . state . keyboardOffset , this . state . containerWidth ) ;
243
+ if ( this . state . keyboardOffset && ( positionDest < this . props . keyboardTopOffset ) ) {
244
+ positionDest = this . props . keyboardTopOffset ;
246
245
}
247
- ) ;
248
- this . state . animOpen . start ( ( ) => {
249
- if ( ! this . state . isOpen && this . props . onOpened ) this . props . onOpened ( ) ;
250
- this . state . isAnimateOpen = false ;
251
- this . state . isOpen = true ;
252
- } ) ;
253
- } )
254
-
246
+ let animOpen = Animated . timing (
247
+ this . state . position ,
248
+ {
249
+ toValue : positionDest ,
250
+ duration : this . props . animationDuration ,
251
+ easing : this . props . easing ,
252
+ }
253
+ ) ;
254
+
255
+ this . setState ( {
256
+ isAnimateOpen : false ,
257
+ animOpen,
258
+ positionDest
259
+ } , ( ) => {
260
+ animOpen . start ( ( ) => {
261
+ if ( ! this . state . isOpen && this . props . onOpened ) this . props . onOpened ( ) ;
262
+ } ) ;
263
+ } ) ;
264
+ } )
265
+ } ) ;
255
266
} ,
256
267
257
268
/*
@@ -260,7 +271,7 @@ var ModalBox = createReactClass({
260
271
stopAnimateClose : function ( ) {
261
272
if ( this . state . isAnimateClose ) {
262
273
if ( this . state . animClose ) this . state . animClose . stop ( ) ;
263
- this . state . isAnimateClose = false ;
274
+ this . setState ( { isAnimateClose : false } ) ;
264
275
}
265
276
} ,
266
277
@@ -274,20 +285,26 @@ var ModalBox = createReactClass({
274
285
if ( this . props . backdrop )
275
286
this . animateBackdropClose ( ) ;
276
287
277
- this . state . isAnimateClose = true ;
278
- this . state . animClose = Animated . timing (
279
- this . state . position ,
280
- {
281
- toValue : this . props . entry === 'top' ? - this . state . containerHeight : this . state . containerHeight ,
282
- duration : this . props . animationDuration
283
- }
284
- ) ;
285
- this . state . animClose . start ( ( ) => {
286
- Keyboard . dismiss ( ) ;
287
- this . state . isAnimateClose = false ;
288
- this . state . isOpen = false ;
289
- this . setState ( { } ) ;
290
- if ( this . props . onClosed ) this . props . onClosed ( ) ;
288
+ this . setState ( {
289
+ isAnimateClose : true ,
290
+ isOpen : false ,
291
+ } , ( ) => {
292
+ let animClose = Animated . timing (
293
+ this . state . position ,
294
+ {
295
+ toValue : this . props . entry === 'top' ? - this . state . containerHeight : this . state . containerHeight ,
296
+ duration : this . props . animationDuration
297
+ }
298
+ ) ;
299
+
300
+ this . setState ( {
301
+ isAnimateClose : false ,
302
+ animClose
303
+ } , ( ) => {
304
+ animClose . start ( ( ) => {
305
+ if ( this . props . onClosed ) this . props . onClosed ( ) ;
306
+ } ) ;
307
+ } ) ;
291
308
} ) ;
292
309
} ,
293
310
@@ -321,8 +338,9 @@ var ModalBox = createReactClass({
321
338
inSwipeArea = false ;
322
339
if ( this . props . entry === 'top' ? - state . dy > this . props . swipeThreshold : state . dy > this . props . swipeThreshold )
323
340
this . animateClose ( ) ;
324
- else
341
+ else if ( ! this . state . isOpen ) {
325
342
this . animateOpen ( ) ;
343
+ }
326
344
} ;
327
345
328
346
var animEvt = Animated . event ( [ null , { customY : this . state . position } ] ) ;
@@ -347,11 +365,13 @@ var ModalBox = createReactClass({
347
365
return true ;
348
366
} ;
349
367
350
- this . state . pan = PanResponder . create ( {
351
- onStartShouldSetPanResponder : onPanStart ,
352
- onPanResponderMove : onPanMove ,
353
- onPanResponderRelease : onPanRelease ,
354
- onPanResponderTerminate : onPanRelease ,
368
+ this . setState ( {
369
+ pan : PanResponder . create ( {
370
+ onStartShouldSetPanResponder : onPanStart ,
371
+ onPanResponderMove : onPanMove ,
372
+ onPanResponderRelease : onPanRelease ,
373
+ onPanResponderTerminate : onPanRelease ,
374
+ } ) ,
355
375
} ) ;
356
376
} ,
357
377
@@ -405,7 +425,7 @@ var ModalBox = createReactClass({
405
425
if ( this . props . backdrop ) {
406
426
backdrop = (
407
427
< TouchableWithoutFeedback onPress = { this . props . backdropPressToClose ? this . close : null } >
408
- < Animated . View style = { [ styles . absolute , { opacity : this . state . backdropOpacity } ] } >
428
+ < Animated . View importantForAccessibility = "no" style = { [ styles . absolute , { opacity : this . state . backdropOpacity } ] } >
409
429
< View style = { [ styles . absolute , { backgroundColor :this . props . backdropColor , opacity : this . props . backdropOpacity } ] } />
410
430
{ this . props . backdropContent || [ ] }
411
431
</ Animated . View >
@@ -425,6 +445,7 @@ var ModalBox = createReactClass({
425
445
onLayout = { this . onViewLayout }
426
446
style = { [ styles . wrapper , size , this . props . style , { transform : [ { translateY : this . state . position } , { translateX : offsetX } ] } ] }
427
447
{ ...this . state . pan . panHandlers } >
448
+ { this . props . backdropPressToClose && < TouchableWithoutFeedback onPress = { this . close } > < View style = { [ styles . absolute ] } /> </ TouchableWithoutFeedback > }
428
449
{ this . props . children }
429
450
</ Animated . View >
430
451
)
@@ -434,23 +455,31 @@ var ModalBox = createReactClass({
434
455
* Render the component
435
456
*/
436
457
render : function ( ) {
458
+
437
459
var visible = this . state . isOpen || this . state . isAnimateOpen || this . state . isAnimateClose ;
438
460
439
461
if ( ! visible ) return < View />
440
462
441
463
var content = (
442
- < View style = { [ styles . transparent , styles . absolute ] } pointerEvents = { 'box-none' } >
464
+ < View importantForAccessibility = "yes" accessibilityViewIsModal = { true } style = { [ styles . transparent , styles . absolute ] } pointerEvents = { 'box-none' } >
443
465
< View style = { { flex : 1 } } pointerEvents = { 'box-none' } onLayout = { this . onContainerLayout } >
444
466
{ visible && this . renderBackdrop ( ) }
445
467
{ visible && this . renderContent ( ) }
446
468
</ View >
447
469
</ View >
448
470
)
449
471
450
- if ( ! this . props . coverScreen ) return content ;
472
+ if ( ! this . props . coverScreen ) return content ;
451
473
452
474
return (
453
- < Modal onRequestClose = { ( ) => this . close ( ) } supportedOrientations = { [ 'landscape' , 'portrait' ] } transparent visible = { visible } >
475
+ < Modal
476
+ onRequestClose = { ( ) => {
477
+ if ( this . props . backButtonClose ) {
478
+ this . close ( )
479
+ }
480
+ } }
481
+ supportedOrientations = { [ 'landscape' , 'portrait' , 'portrait-upside-down' ] } transparent visible = { visible }
482
+ >
454
483
{ content }
455
484
</ Modal >
456
485
) ;
0 commit comments