From aca303c86737a9804adb24c0a6a5a17904f76839 Mon Sep 17 00:00:00 2001 From: Nelson Lopes Silva <5671236+nflsilva@users.noreply.github.com> Date: Thu, 15 Jul 2021 17:44:09 +0100 Subject: [PATCH 1/2] Removed part of the logic that destroys a WebView eachtime a link is opened. --- src/ios/CDVWKInAppBrowser.m | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m index aacf19297..036a153a3 100644 --- a/src/ios/CDVWKInAppBrowser.m +++ b/src/ios/CDVWKInAppBrowser.m @@ -661,19 +661,9 @@ - (void)browserExit self.callbackId = nil; } - [self.inAppBrowserViewController.configuration.userContentController removeScriptMessageHandlerForName:IAB_BRIDGE_NAME]; - self.inAppBrowserViewController.configuration = nil; - [self.inAppBrowserViewController.webView stopLoading]; - [self.inAppBrowserViewController.webView removeFromSuperview]; - [self.inAppBrowserViewController.webView setUIDelegate:nil]; - [self.inAppBrowserViewController.webView setNavigationDelegate:nil]; - self.inAppBrowserViewController.webView = nil; - - // Set navigationDelegate to nil to ensure no callbacks are received from it. - self.inAppBrowserViewController.navigationDelegate = nil; - self.inAppBrowserViewController = nil; - + [self.inAppBrowserViewController navigateTo:([NSURL URLWithString:@"about:blank"])]; + // Set tmpWindow to hidden to make main webview responsive to touch again // Based on https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow self->tmpWindow.hidden = YES; From e5c572a931a07a112cd9fb0af65d2253bbcd3b80 Mon Sep 17 00:00:00 2001 From: Nelson Lopes Silva <5671236+nflsilva@users.noreply.github.com> Date: Thu, 15 Jul 2021 22:51:25 +0100 Subject: [PATCH 2/2] Updated WebView fix --- src/ios/CDVWKInAppBrowser.h | 1 + src/ios/CDVWKInAppBrowser.m | 32 +++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/ios/CDVWKInAppBrowser.h b/src/ios/CDVWKInAppBrowser.h index f8263f707..7a3afbf27 100644 --- a/src/ios/CDVWKInAppBrowser.h +++ b/src/ios/CDVWKInAppBrowser.h @@ -75,6 +75,7 @@ - (void)showLocationBar:(BOOL)show; - (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition; - (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex; +- (void)updateViews: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary*) settings; - (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary*) settings; diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m index 036a153a3..cdd05b384 100644 --- a/src/ios/CDVWKInAppBrowser.m +++ b/src/ios/CDVWKInAppBrowser.m @@ -200,11 +200,13 @@ - (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options if (self.inAppBrowserViewController == nil) { self.inAppBrowserViewController = [[CDVWKInAppBrowserViewController alloc] initWithBrowserOptions: browserOptions andSettings:self.commandDelegate.settings]; self.inAppBrowserViewController.navigationDelegate = self; - if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) { self.inAppBrowserViewController.orientationDelegate = (UIViewController *)self.viewController; } } + else { + [self.inAppBrowserViewController updateViews:browserOptions andSettings:self.commandDelegate.settings]; + } [self.inAppBrowserViewController showLocationBar:browserOptions.location]; [self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition]; @@ -661,8 +663,19 @@ - (void)browserExit self.callbackId = nil; } + [self.inAppBrowserViewController.configuration.userContentController removeScriptMessageHandlerForName:IAB_BRIDGE_NAME]; + self.inAppBrowserViewController.configuration = nil; + [self.inAppBrowserViewController.webView stopLoading]; [self.inAppBrowserViewController navigateTo:([NSURL URLWithString:@"about:blank"])]; + [self.inAppBrowserViewController.webView removeFromSuperview]; + [self.inAppBrowserViewController.webView setUIDelegate:nil]; + [self.inAppBrowserViewController.webView setNavigationDelegate:nil]; + + [self.inAppBrowserViewController.spinner removeFromSuperview]; + [self.inAppBrowserViewController.toolbar removeFromSuperview]; + [self.inAppBrowserViewController.addressLabel removeFromSuperview]; + [self.inAppBrowserViewController.backgroundView removeFromSuperview]; // Set tmpWindow to hidden to make main webview responsive to touch again // Based on https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow @@ -705,10 +718,16 @@ - (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettin return self; } --(void)dealloc { +- (void)dealloc { //NSLog(@"dealloc"); } +- (void)updateViews: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary*) settings { + _browserOptions = browserOptions; + _settings = settings; + [self createViews]; +} + - (void)createViews { // We create the views in code for primarily for ease of upgrades and not requiring an external .xib to be included @@ -738,9 +757,12 @@ - (void)createViews configuration.mediaPlaybackRequiresUserAction = _browserOptions.mediaplaybackrequiresuseraction; } - - - self.webView = [[WKWebView alloc] initWithFrame:webViewBounds configuration:configuration]; + if(self.webView == nil) { + self.webView = [[WKWebView alloc] initWithFrame:webViewBounds configuration:configuration]; + } + else { + self.webView.frame = webViewBounds; + } [self.view addSubview:self.webView]; [self.view sendSubviewToBack:self.webView];