Skip to content

Commit

Permalink
Fix modals not being dismissed properly
Browse files Browse the repository at this point in the history
Improve the algorithm for determining the view controller for presentation of
RCTModalHostViewController.

The problem was that RCTModalHostViewManager always used the first responder
view controller (`[modalHostView reactViewController]`), whereas it is possible
that such controller also had presented another view controller on top of
itself (and that one could present yet another VC, and so on). So we walk
through the presentedViewController list to find the top-most presented VC.
  • Loading branch information
sryze committed Oct 13, 2019
1 parent 6376951 commit 07a34b0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion React/Views/RCTModalHostViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,19 @@ - (void)presentModalHostView:(RCTModalHostView *)modalHostView withViewControlle
if (_presentationBlock) {
_presentationBlock([modalHostView reactViewController], viewController, animated, completionBlock);
} else {
[[modalHostView reactViewController] presentViewController:viewController animated:animated completion:completionBlock];
UIViewController *topViewController = [modalHostView reactViewController];
while (topViewController.presentedViewController != nil) {
if ([topViewController.presentedViewController isKindOfClass:UIAlertController.class]) {
// Don't present on top of UIAlertController, this will mess it up:
// https://stackoverflow.com/questions/27028983/uialertcontroller-is-moved-to-buggy-position-at-top-of-screen-when-it-calls-pre
[topViewController dismissViewControllerAnimated:animated completion:^{
[topViewController presentViewController:viewController animated:animated completion:completionBlock];
}];
return;
}
topViewController = topViewController.presentedViewController;
}
[topViewController presentViewController:viewController animated:animated completion:completionBlock];
}
}

Expand Down

0 comments on commit 07a34b0

Please sign in to comment.