diff --git a/Examples/UIExplorer/ModalExample.js b/Examples/UIExplorer/ModalExample.js index 3202cb62243..eb925b5eb53 100644 --- a/Examples/UIExplorer/ModalExample.js +++ b/Examples/UIExplorer/ModalExample.js @@ -143,6 +143,7 @@ var styles = StyleSheet.create({ }, innerContainer: { borderRadius: 10, + alignItems: 'center', }, row: { alignItems: 'center', @@ -158,6 +159,7 @@ var styles = StyleSheet.create({ borderRadius: 5, flex: 1, height: 44, + alignSelf: 'stretch', justifyContent: 'center', overflow: 'hidden', }, diff --git a/Libraries/Modal/Modal.js b/Libraries/Modal/Modal.js index f9311066c11..dfbfdb68554 100644 --- a/Libraries/Modal/Modal.js +++ b/Libraries/Modal/Modal.js @@ -59,9 +59,14 @@ class Modal extends React.Component { Modal.propTypes = { animated: PropTypes.bool, transparent: PropTypes.bool, + visible: PropTypes.bool, onDismiss: PropTypes.func, }; +Modal.defaultProps = { + visible: true, +}; + var styles = StyleSheet.create({ modal: { position: 'absolute', diff --git a/React/Views/RCTModalHostView.m b/React/Views/RCTModalHostView.m index 9b755e515ad..3fed3f3210d 100644 --- a/React/Views/RCTModalHostView.m +++ b/React/Views/RCTModalHostView.m @@ -76,15 +76,22 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:coder) } } +- (void)didMoveToWindow +{ + [super didMoveToWindow]; + + if (!_isPresented && self.window) { + RCTAssert(self.reactViewController, @"Can't present modal view controller without a presenting view controller"); + [self.reactViewController presentViewController:_modalViewController animated:self.animated completion:nil]; + _isPresented = YES; + } +} + - (void)didMoveToSuperview { [super didMoveToSuperview]; - if (self.superview) { - RCTAssert(self.reactViewController, @"Can't present modal view controller without a presenting view controller"); - [self.reactViewController presentViewController:_modalViewController animated:self.animated completion:nil]; - _isPresented = YES; - } else { + if (_isPresented && !self.superview) { [self dismissModalViewController]; } }