Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions packages/react-native/Libraries/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,18 @@ class Modal extends React.Component<Props, State> {
this._eventSubscription = ModalEventEmitter.addListener(
'modalDismissed',
event => {
if (event.modalID === this._identifier && this.props.onDismiss) {
this.setState({isRendered: false}, () => {
if (this.props.onDismiss) {
this.props.onDismiss();
}
});
}
this.setState({isRendered: false}, () => {
if (event.modalID === this._identifier && this.props.onDismiss) {
this.props.onDismiss();
}
});
},
);
}
}

componentWillUnmount() {
this.setState({isRendered: false});
if (this._eventSubscription) {
this._eventSubscription.remove();
}
Expand Down
7 changes: 6 additions & 1 deletion packages/react-native/React/Views/RCTModalHostViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ - (void)dismissModalHostView:(RCTModalHostView *)modalHostView
dispatch_async(dispatch_get_main_queue(), ^{
if (self->_dismissalBlock) {
self->_dismissalBlock([modalHostView reactViewController], viewController, animated, completionBlock);
} else {
} else if (viewController.presentingViewController) {
[viewController.presentingViewController dismissViewControllerAnimated:animated completion:completionBlock];
} else {
// Make sure to call the completion block in case the presenting view controller is nil
// In an internal app we have a use case where a modal presents another view without bein dismissed
// This, somehow, invalidate the presenting view controller and the modal remains always visible.
completionBlock();
}
});
}
Expand Down