Skip to content

Commit

Permalink
Make <Modal> visible by default
Browse files Browse the repository at this point in the history
Summary: Make <Modal> visible by default and fix the scenario where we present a modal immediately when adding it to the view hierarchy.

Closes facebook#3724
Closes facebook#2952

public

Reviewed By: nicklockwood

Differential Revision: D2595938

fb-gh-sync-id: 1571790d36fe486f1fbbed9f2d66f1e6add73d91
  • Loading branch information
javache authored and Tj committed Nov 9, 2015
1 parent 48599c0 commit 649015c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Examples/UIExplorer/ModalExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ var styles = StyleSheet.create({
},
innerContainer: {
borderRadius: 10,
alignItems: 'center',
},
row: {
alignItems: 'center',
Expand All @@ -158,6 +159,7 @@ var styles = StyleSheet.create({
borderRadius: 5,
flex: 1,
height: 44,
alignSelf: 'stretch',
justifyContent: 'center',
overflow: 'hidden',
},
Expand Down
5 changes: 5 additions & 0 deletions Libraries/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
15 changes: 11 additions & 4 deletions React/Views/RCTModalHostView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down

0 comments on commit 649015c

Please sign in to comment.