Fixed issue with alert not being presented when modal window is hidden

Reviewed By: ryanolsonk

Differential Revision: D2658537

fb-gh-sync-id: 94bb311142005cfacc7b7612c17309835eeb980a
This commit is contained in:
Nick Lockwood 2015-11-16 10:20:34 -08:00 коммит произвёл facebook-github-bot-4
Родитель 136d79f4d6
Коммит 8b81bb7be5
1 изменённых файлов: 17 добавлений и 17 удалений

Просмотреть файл

@ -85,25 +85,13 @@ RCT_EXPORT_METHOD(alertWithArgs:(NSDictionary *)args
return; return;
} }
if (RCTRunningInAppExtension()) {
return;
}
UIViewController *presentingController = RCTKeyWindow().rootViewController;
if (presentingController == nil) {
RCTLogError(@"Tried to display alert view but there is no application window. args: %@", 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 __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
if ([UIAlertController class] == nil) { // TODO: we've encountered some bug when presenting alerts on top of a window that is subsequently
// dismissed. As a temporary solution to this, we'll use UIAlertView preferentially if it's available.
BOOL preferAlertView = (!RCTRunningInAppExtension() && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
if (preferAlertView || [UIAlertController class] == nil) {
UIAlertView *alertView = RCTAlertView(title, nil, self, nil, nil); UIAlertView *alertView = RCTAlertView(title, nil, self, nil, nil);
NSMutableArray<NSString *> *buttonKeys = [[NSMutableArray alloc] initWithCapacity:buttons.count]; NSMutableArray<NSString *> *buttonKeys = [[NSMutableArray alloc] initWithCapacity:buttons.count];
@ -141,6 +129,18 @@ RCT_EXPORT_METHOD(alertWithArgs:(NSDictionary *)args
#endif #endif
{ {
UIViewController *presentingController = RCTKeyWindow().rootViewController;
if (presentingController == nil) {
RCTLogError(@"Tried to display alert view but there is no application window. args: %@", 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;
}
UIAlertController *alertController = UIAlertController *alertController =
[UIAlertController alertControllerWithTitle:title [UIAlertController alertControllerWithTitle:title
message:nil message:nil