From 6ab2719bff9753f533d7bb91f848d59ddece3e75 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 30 Oct 2015 17:03:23 -0700 Subject: [PATCH] Make visible by default Summary: Make visible by default and fix the scenario where we present a modal immediately when adding it to the view hierarchy. Closes #3724 Closes #2952 public Reviewed By: nicklockwood Differential Revision: D2595938 fb-gh-sync-id: 1571790d36fe486f1fbbed9f2d66f1e6add73d91 --- Examples/UIExplorer/ModalExample.js | 2 ++ Libraries/Modal/Modal.js | 5 +++++ React/Views/RCTModalHostView.m | 17 ++++++++++++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Examples/UIExplorer/ModalExample.js b/Examples/UIExplorer/ModalExample.js index 3202cb622..eb925b5eb 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 f9311066c..dfbfdb685 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 9b755e515..3fed3f321 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]; } }