From 51a5b60a1a4773e6db8798ff4b2eac02dc75c127 Mon Sep 17 00:00:00 2001 From: Ryan Olson Date: Wed, 11 Nov 2015 09:27:16 -0800 Subject: [PATCH] Fix showing alerts when modals are presented Reviewed By: nicklockwood Differential Revision: D2638505 fb-gh-sync-id: ebecc82baa46be4302fc8d3231f859de572eda10 --- React/Modules/RCTAlertManager.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/React/Modules/RCTAlertManager.m b/React/Modules/RCTAlertManager.m index 7c6ef18f54..3da550c4f9 100644 --- a/React/Modules/RCTAlertManager.m +++ b/React/Modules/RCTAlertManager.m @@ -95,6 +95,12 @@ RCT_EXPORT_METHOD(alertWithArgs:(NSDictionary *)args return; } + // Walk the chain up to get the topmost modal view controller. If modals are presented, + // the root view controller's view might not be in the window hierarchy, and presenting from it will fail. + while (presentingController.presentedViewController) { + presentingController = presentingController.presentedViewController; + } + #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0 if ([UIAlertController class] == nil) {