Skip to content

Commit

Permalink
Fix dismissal on the Old Architecture
Browse files Browse the repository at this point in the history
Summary:
The recent change to make onDismiss work on Fabric broke the Modal on Paper (see [this comment](https://www.internalfb.com/diff/D52959996?dst_version_fbid=236415652884499&transaction_fbid=896066412296150)).

This change will fix that behavior.

The problem was that we were resetting the `isRendered` state only when the Modal receives the event from the Event emitter AND if it has the `onDismiss` callback set.
However, we should hide the component in any case if the ids match, and invoke the onDismiss if it is set.

## Changelog
[iOS][Fixed] - Make sure that Modal is dismissed correctly in Paper

Reviewed By: janeli-100005636499545

Differential Revision: D53686165

fbshipit-source-id: a1de0b29dca7c099e9fa0282ec80cae9a8fd6bc3
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Feb 13, 2024
1 parent 94bfde4 commit 4236538
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
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

0 comments on commit 4236538

Please sign in to comment.