From 1e0a2cbf1211d85e11b87703f7bae9de936727ce Mon Sep 17 00:00:00 2001 From: Mike Hartington Date: Fri, 15 May 2020 11:21:24 -0400 Subject: [PATCH 1/9] feat(ios): improve webview background experience --- .../Capacitor/CAPBridgeViewController.swift | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index 4c89f1417..a447d793c 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -8,13 +8,13 @@ import WebKit import Cordova public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScriptMessageHandler, WKUIDelegate, WKNavigationDelegate { - + private var webView: WKWebView? - + public var bridgedWebView: WKWebView? { return webView } - + public var bridgedViewController: UIViewController? { return self } @@ -23,19 +23,19 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr private var allowNavigationConfig: [String]? private var basePath: String = "" private let assetsFolder = "public" - + private var isStatusBarVisible = true private var statusBarStyle: UIStatusBarStyle = .default private var statusBarAnimation: UIStatusBarAnimation = .slide @objc public var supportedOrientations: Array = [] - + @objc public var startDir = "" @objc public var config: String? // Construct the Capacitor runtime public var bridge: CAPBridge? private var handler: CAPAssetHandler? - + override public func loadView() { let configUrl = Bundle.main.url(forResource: "config", withExtension: "xml") let configParser = XMLParser(contentsOf: configUrl!)!; @@ -44,7 +44,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr guard let startPath = self.getStartPath() else { return } - + setStatusBarDefaults() setScreenOrientationDefaults() let capConfig = CAPConfig(self.config) @@ -65,7 +65,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr o.add(self, name: "bridge") webViewConfiguration.userContentController = o - + configureWebView(configuration: webViewConfiguration) if let appendUserAgent = (capConfig.getValue("ios.appendUserAgent") as? String) ?? (capConfig.getValue("appendUserAgent") as? String) { @@ -89,15 +89,21 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr } webView?.configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs") view = webView - + setKeyboardRequiresUserInteraction(false) - + bridge = CAPBridge(self, o, capConfig, specifiedScheme) + webView?.isOpaque = false if let backgroundColor = (bridge!.config.getValue("ios.backgroundColor") as? String) ?? (bridge!.config.getValue("backgroundColor") as? String) { - webView?.backgroundColor = UIColor(fromHex: backgroundColor) - webView?.scrollView.backgroundColor = UIColor(fromHex: backgroundColor) + if #available(iOS 13.0, *) { + webView?.backgroundColor = UIColor.systemBackground + } else { + webView?.backgroundColor = UIColor(fromHex: backgroundColor) + }; + webView?.scrollView.backgroundColor = UIColor(fromHex: backgroundColor) } + if let overrideUserAgent = (bridge!.config.getValue("ios.overrideUserAgent") as? String) ?? (bridge!.config.getValue("overrideUserAgent") as? String) { webView?.customUserAgent = overrideUserAgent } @@ -160,13 +166,13 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr func printLoadError() { let fullStartPath = URL(fileURLWithPath: assetsFolder).appendingPathComponent(startDir) - + CAPLog.print("⚡️ ERROR: Unable to load \(fullStartPath.relativePath)/index.html") CAPLog.print("⚡️ This file is the root of your web app and must exist before") CAPLog.print("⚡️ Capacitor can run. Ensure you've run capacitor copy at least") CAPLog.print("⚡️ or, if embedding, that this directory exists as a resource directory.") } - + func fatalLoadError() -> Never { printLoadError() exit(1) @@ -256,7 +262,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DecidePolicyForNavigationAction.name()), object: navigationAction) let navUrl = navigationAction.request.url! - + /* * Give plugins the chance to handle the url */ @@ -278,7 +284,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr } } } - + if let allowNavigation = allowNavigationConfig, let requestHost = navUrl.host { for pattern in allowNavigation { if matchHost(host: requestHost, pattern: pattern.lowercased()) { @@ -480,9 +486,9 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr } public func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (String?) -> Void) { - + let alertController = UIAlertController(title: nil, message: prompt, preferredStyle: .alert) - + alertController.addTextField { (textField) in textField.text = defaultText } @@ -497,9 +503,9 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr })) alertController.addAction(UIAlertAction(title: "Cancel", style: .default, handler: { (action) in - + completionHandler(nil) - + })) self.present(alertController, animated: true, completion: nil) @@ -551,7 +557,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr /** * Add hooks to detect failed HTTP requests - + func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) { @@ -564,5 +570,5 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr } } */ - + } From 50a50409f1e85fcaac5b0540549f5bd2cf21d1e2 Mon Sep 17 00:00:00 2001 From: Mike Hartington Date: Thu, 2 Jul 2020 13:13:33 -0400 Subject: [PATCH 2/9] updates based on feedback --- .../App/App/Base.lproj/LaunchScreen.storyboard | 13 ++++++++----- .../Capacitor/CAPBridgeViewController.swift | 9 ++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ios-template/App/App/Base.lproj/LaunchScreen.storyboard b/ios-template/App/App/Base.lproj/LaunchScreen.storyboard index 412ea5f7a..e7ae5d780 100644 --- a/ios-template/App/App/Base.lproj/LaunchScreen.storyboard +++ b/ios-template/App/App/Base.lproj/LaunchScreen.storyboard @@ -1,11 +1,10 @@ - - - - + + - + + @@ -16,6 +15,7 @@ + @@ -25,5 +25,8 @@ + + + diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index a447d793c..2db2fd8eb 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -95,12 +95,11 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr bridge = CAPBridge(self, o, capConfig, specifiedScheme) webView?.isOpaque = false + if #available(iOS 13.0, *) { + webView?.backgroundColor = UIColor.systemBackground + } if let backgroundColor = (bridge!.config.getValue("ios.backgroundColor") as? String) ?? (bridge!.config.getValue("backgroundColor") as? String) { - if #available(iOS 13.0, *) { - webView?.backgroundColor = UIColor.systemBackground - } else { - webView?.backgroundColor = UIColor(fromHex: backgroundColor) - }; + webView?.backgroundColor = UIColor(fromHex: backgroundColor) webView?.scrollView.backgroundColor = UIColor(fromHex: backgroundColor) } From c4cf61280ed2a72af835f6217e83edee1bb78fbf Mon Sep 17 00:00:00 2001 From: Mike Hartington Date: Thu, 2 Jul 2020 16:32:33 -0400 Subject: [PATCH 3/9] apply feedback --- .../Capacitor/CAPBridgeViewController.swift | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index 2db2fd8eb..8e5daaf15 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -8,13 +8,13 @@ import WebKit import Cordova public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScriptMessageHandler, WKUIDelegate, WKNavigationDelegate { - + private var webView: WKWebView? - + public var bridgedWebView: WKWebView? { return webView } - + public var bridgedViewController: UIViewController? { return self } @@ -23,19 +23,19 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr private var allowNavigationConfig: [String]? private var basePath: String = "" private let assetsFolder = "public" - + private var isStatusBarVisible = true private var statusBarStyle: UIStatusBarStyle = .default private var statusBarAnimation: UIStatusBarAnimation = .slide @objc public var supportedOrientations: Array = [] - + @objc public var startDir = "" @objc public var config: String? // Construct the Capacitor runtime public var bridge: CAPBridge? private var handler: CAPAssetHandler? - + override public func loadView() { let configUrl = Bundle.main.url(forResource: "config", withExtension: "xml") let configParser = XMLParser(contentsOf: configUrl!)!; @@ -44,7 +44,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr guard let startPath = self.getStartPath() else { return } - + setStatusBarDefaults() setScreenOrientationDefaults() let capConfig = CAPConfig(self.config) @@ -65,7 +65,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr o.add(self, name: "bridge") webViewConfiguration.userContentController = o - + configureWebView(configuration: webViewConfiguration) if let appendUserAgent = (capConfig.getValue("ios.appendUserAgent") as? String) ?? (capConfig.getValue("appendUserAgent") as? String) { @@ -89,20 +89,20 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr } webView?.configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs") view = webView - + setKeyboardRequiresUserInteraction(false) - + bridge = CAPBridge(self, o, capConfig, specifiedScheme) - webView?.isOpaque = false - if #available(iOS 13.0, *) { - webView?.backgroundColor = UIColor.systemBackground - } if let backgroundColor = (bridge!.config.getValue("ios.backgroundColor") as? String) ?? (bridge!.config.getValue("backgroundColor") as? String) { - webView?.backgroundColor = UIColor(fromHex: backgroundColor) - webView?.scrollView.backgroundColor = UIColor(fromHex: backgroundColor) + webView?.backgroundColor = UIColor(fromHex: backgroundColor) + webView?.scrollView.backgroundColor = UIColor(fromHex: backgroundColor) + } else if #available(iOS 13, *) { + // Use the system background colors if background is not set by user + webView?.backgroundColor = UIColor.systemBackground + webView?.scrollView.backgroundColor = UIColor.systemBackground } - + if let overrideUserAgent = (bridge!.config.getValue("ios.overrideUserAgent") as? String) ?? (bridge!.config.getValue("overrideUserAgent") as? String) { webView?.customUserAgent = overrideUserAgent } @@ -165,19 +165,24 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr func printLoadError() { let fullStartPath = URL(fileURLWithPath: assetsFolder).appendingPathComponent(startDir) - + CAPLog.print("⚡️ ERROR: Unable to load \(fullStartPath.relativePath)/index.html") CAPLog.print("⚡️ This file is the root of your web app and must exist before") CAPLog.print("⚡️ Capacitor can run. Ensure you've run capacitor copy at least") CAPLog.print("⚡️ or, if embedding, that this directory exists as a resource directory.") } - + func fatalLoadError() -> Never { printLoadError() exit(1) } func loadWebView() { + // Set the webview to transparent when loaded + // This prevents any white flashes when loading content from the webview + // this gets set back on success or failure due to performance reasons + webView?.isOpaque = false + let fullStartPath = URL(fileURLWithPath: assetsFolder).appendingPathComponent(startDir).appendingPathComponent("index") if Bundle.main.path(forResource: fullStartPath.relativePath, ofType: "html") == nil { fatalLoadError() @@ -261,7 +266,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DecidePolicyForNavigationAction.name()), object: navigationAction) let navUrl = navigationAction.request.url! - + /* * Give plugins the chance to handle the url */ @@ -283,7 +288,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr } } } - + if let allowNavigation = allowNavigationConfig, let requestHost = navUrl.host { for pattern in allowNavigation { if matchHost(host: requestHost, pattern: pattern.lowercased()) { @@ -303,10 +308,12 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr } public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { + webView?isOpaque = true CAPLog.print("⚡️ WebView loaded") } public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { + webView?isOpaque = true CAPLog.print("⚡️ WebView failed to load") CAPLog.print("⚡️ Error: " + error.localizedDescription) } @@ -485,9 +492,9 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr } public func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (String?) -> Void) { - + let alertController = UIAlertController(title: nil, message: prompt, preferredStyle: .alert) - + alertController.addTextField { (textField) in textField.text = defaultText } @@ -502,9 +509,9 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr })) alertController.addAction(UIAlertAction(title: "Cancel", style: .default, handler: { (action) in - + completionHandler(nil) - + })) self.present(alertController, animated: true, completion: nil) @@ -556,7 +563,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr /** * Add hooks to detect failed HTTP requests - + func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) { @@ -569,5 +576,5 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr } } */ - + } From b505676dbe3b13b572daf4071d2d7e2c305d4f4b Mon Sep 17 00:00:00 2001 From: Mike Hartington Date: Thu, 2 Jul 2020 16:44:51 -0400 Subject: [PATCH 4/9] fix build --- ios/Capacitor/Capacitor/CAPBridgeViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index 8e5daaf15..d7408e101 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -308,12 +308,12 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr } public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { - webView?isOpaque = true + webView?.isOpaque = true CAPLog.print("⚡️ WebView loaded") } public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { - webView?isOpaque = true + webView?.isOpaque = true CAPLog.print("⚡️ WebView failed to load") CAPLog.print("⚡️ Error: " + error.localizedDescription) } From 109a7c3c8c163cc6eb51f557b86ab8aea46a1fb6 Mon Sep 17 00:00:00 2001 From: Mike Hartington Date: Thu, 2 Jul 2020 16:47:50 -0400 Subject: [PATCH 5/9] actually fix build --- ios/Capacitor/Capacitor/CAPBridgeViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index d7408e101..2e6aa9a85 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -308,12 +308,12 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr } public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { - webView?.isOpaque = true + webView.isOpaque = true CAPLog.print("⚡️ WebView loaded") } public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { - webView?.isOpaque = true + webView.isOpaque = true CAPLog.print("⚡️ WebView failed to load") CAPLog.print("⚡️ Error: " + error.localizedDescription) } From 3fa5be932d1118cb8b69a6682182bc3aad43c563 Mon Sep 17 00:00:00 2001 From: Ian Keith Date: Fri, 10 Jul 2020 15:23:20 -0400 Subject: [PATCH 6/9] Added state to only adjust the webview's `isOpaque` property on initial load and preserve the value in case it was modified by a plugin. --- .../Capacitor/CAPBridgeViewController.swift | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index 2e6aa9a85..16bf498e5 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -24,6 +24,13 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr private var basePath: String = "" private let assetsFolder = "public" + private enum WebViewLoadingState { + case unloaded + case initialLoad(isOpaque: Bool) + case subsequentLoad + } + private var webViewLoadingState = WebViewLoadingState.unloaded + private var isStatusBarVisible = true private var statusBarStyle: UIStatusBarStyle = .default private var statusBarAnimation: UIStatusBarAnimation = .slide @@ -178,10 +185,15 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr } func loadWebView() { - // Set the webview to transparent when loaded - // This prevents any white flashes when loading content from the webview - // this gets set back on success or failure due to performance reasons - webView?.isOpaque = false + // Set the webview to be not opaque on the inital load. This prevents + // the webview from showing a white background, which is its default + // loading display, as that can appear as a screen flash. This might + // have already been set by something else, like a plugin, so we want + // to save the current value to reset it on success or failure. + if case .unloaded = webViewLoadingState { + webViewLoadingState = .initialLoad(isOpaque: webView.isOpaque) + webView?.isOpaque = false + } let fullStartPath = URL(fileURLWithPath: assetsFolder).appendingPathComponent(startDir).appendingPathComponent("index") if Bundle.main.path(forResource: fullStartPath.relativePath, ofType: "html") == nil { @@ -308,12 +320,18 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr } public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { - webView.isOpaque = true + if case .initialLoad(let isOpaque) = webViewLoadingState { + webView.isOpaque = isOpaque + webViewLoadingState = .subsequentLoad + } CAPLog.print("⚡️ WebView loaded") } public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { - webView.isOpaque = true + if case .initialLoad(let isOpaque) = webViewLoadingState { + webView.isOpaque = isOpaque + webViewLoadingState = .subsequentLoad + } CAPLog.print("⚡️ WebView failed to load") CAPLog.print("⚡️ Error: " + error.localizedDescription) } From 112354ae10085ff059e244d3157d9dae98faa8b2 Mon Sep 17 00:00:00 2001 From: Ian Keith Date: Fri, 10 Jul 2020 15:23:33 -0400 Subject: [PATCH 7/9] Update ios/Capacitor/Capacitor/CAPBridgeViewController.swift Co-authored-by: jcesarmobile --- ios/Capacitor/Capacitor/CAPBridgeViewController.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index 2e6aa9a85..b25c9cc85 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -98,9 +98,9 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr webView?.backgroundColor = UIColor(fromHex: backgroundColor) webView?.scrollView.backgroundColor = UIColor(fromHex: backgroundColor) } else if #available(iOS 13, *) { - // Use the system background colors if background is not set by user - webView?.backgroundColor = UIColor.systemBackground - webView?.scrollView.backgroundColor = UIColor.systemBackground + // Use the system background colors if background is not set by user + webView?.backgroundColor = UIColor.systemBackground + webView?.scrollView.backgroundColor = UIColor.systemBackground } if let overrideUserAgent = (bridge!.config.getValue("ios.overrideUserAgent") as? String) ?? (bridge!.config.getValue("overrideUserAgent") as? String) { From 816803d9435062f8ac4690809bed31171eac4b26 Mon Sep 17 00:00:00 2001 From: Ian Keith Date: Fri, 10 Jul 2020 15:46:41 -0400 Subject: [PATCH 8/9] Fixing optional handling. --- ios/Capacitor/Capacitor/CAPBridgeViewController.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index 7f9653389..ba1291114 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -190,9 +190,9 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr // loading display, as that can appear as a screen flash. This might // have already been set by something else, like a plugin, so we want // to save the current value to reset it on success or failure. - if case .unloaded = webViewLoadingState { + if let webView = webView, case .unloaded = webViewLoadingState { webViewLoadingState = .initialLoad(isOpaque: webView.isOpaque) - webView?.isOpaque = false + webView.isOpaque = false } let fullStartPath = URL(fileURLWithPath: assetsFolder).appendingPathComponent(startDir).appendingPathComponent("index") @@ -321,7 +321,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { if case .initialLoad(let isOpaque) = webViewLoadingState { - webView.isOpaque = isOpaque + webView?.isOpaque = isOpaque webViewLoadingState = .subsequentLoad } CAPLog.print("⚡️ WebView loaded") @@ -329,7 +329,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { if case .initialLoad(let isOpaque) = webViewLoadingState { - webView.isOpaque = isOpaque + webView?.isOpaque = isOpaque webViewLoadingState = .subsequentLoad } CAPLog.print("⚡️ WebView failed to load") From fc428c27c05b2dac6fb0ba68621c619866ac1891 Mon Sep 17 00:00:00 2001 From: Ian Keith Date: Fri, 10 Jul 2020 15:53:14 -0400 Subject: [PATCH 9/9] Fixing optional --- ios/Capacitor/Capacitor/CAPBridgeViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index ba1291114..1a6ef6a57 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -321,7 +321,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { if case .initialLoad(let isOpaque) = webViewLoadingState { - webView?.isOpaque = isOpaque + webView.isOpaque = isOpaque webViewLoadingState = .subsequentLoad } CAPLog.print("⚡️ WebView loaded") @@ -329,7 +329,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { if case .initialLoad(let isOpaque) = webViewLoadingState { - webView?.isOpaque = isOpaque + webView.isOpaque = isOpaque webViewLoadingState = .subsequentLoad } CAPLog.print("⚡️ WebView failed to load")