From 677888307f7854f68011929d0660f1ab370e189b Mon Sep 17 00:00:00 2001 From: Dave Alden Date: Thu, 26 Sep 2019 10:44:27 +0100 Subject: [PATCH] Fixes for iOS 13 --- src/ios/CDVThemeableBrowser.h | 1 + src/ios/CDVThemeableBrowser.m | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/ios/CDVThemeableBrowser.h b/src/ios/CDVThemeableBrowser.h index ed59e22f1..8294468d1 100644 --- a/src/ios/CDVThemeableBrowser.h +++ b/src/ios/CDVThemeableBrowser.h @@ -63,6 +63,7 @@ @class CDVThemeableBrowserViewController; @interface CDVThemeableBrowser : CDVPlugin { + UIWindow * tmpWindow; BOOL _injectedIframeBridge; } diff --git a/src/ios/CDVThemeableBrowser.m b/src/ios/CDVThemeableBrowser.m index 404b4076f..5fd9fa0bc 100644 --- a/src/ios/CDVThemeableBrowser.m +++ b/src/ios/CDVThemeableBrowser.m @@ -329,16 +329,27 @@ - (void)show:(CDVInvokedUrlCommand*)command withAnimation:(BOOL)animated initWithRootViewController:self.themeableBrowserViewController]; nav.orientationDelegate = self.themeableBrowserViewController; nav.navigationBarHidden = YES; + if (@available(iOS 13.0, *)) { + nav.modalInPresentation = true; + nav.modalPresentationStyle = UIModalPresentationOverFullScreen; + } + + __weak CDVThemeableBrowser* weakSelf = self; + // Run later to avoid the "took a long time" log message. dispatch_async(dispatch_get_main_queue(), ^{ if (self.themeableBrowserViewController != nil) { - CGRect frame = [[UIScreen mainScreen] bounds]; - UIWindow *tmpWindow = [[UIWindow alloc] initWithFrame:frame]; + __strong __typeof(weakSelf) strongSelf = weakSelf; + if (!strongSelf->tmpWindow) { + CGRect frame = [[UIScreen mainScreen] bounds]; + strongSelf->tmpWindow = [[UIWindow alloc] initWithFrame:frame]; + } + UIViewController *tmpController = [[UIViewController alloc] init]; - [tmpWindow setRootViewController:tmpController]; - [tmpWindow setWindowLevel:UIWindowLevelNormal]; + [strongSelf->tmpWindow setRootViewController:tmpController]; + - [tmpWindow makeKeyAndVisible]; + [strongSelf->tmpWindow makeKeyAndVisible]; [tmpController presentViewController:nav animated:YES completion:nil]; } }); @@ -626,6 +637,8 @@ - (void)browserExit // Don't recycle the ViewController since it may be consuming a lot of memory. // Also - this is required for the PDF/User-Agent bug work-around. self.themeableBrowserViewController = nil; + + self.callbackId = nil; self.callbackIdPattern = nil;