diff --git a/Examples/UIExplorer/ModalExample.js b/Examples/UIExplorer/ModalExample.js index 3202cb62243310..eb925b5eb531fb 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 f9311066c11a72..dfbfdb68554268 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 9b755e515ad0ce..3fed3f3210d820 100644 --- a/React/Views/RCTModalHostView.m +++ b/React/Views/RCTModalHostView.m @@ -76,15 +76,22 @@ - (void)dismissModalViewController } } -- (void)didMoveToSuperview +- (void)didMoveToWindow { - [super didMoveToSuperview]; + [super didMoveToWindow]; - if (self.superview) { + 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; - } else { + } +} + +- (void)didMoveToSuperview +{ + [super didMoveToSuperview]; + + if (_isPresented && !self.superview) { [self dismissModalViewController]; } }