@@ -24,6 +24,13 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
2424 private var basePath : String = " "
2525 private let assetsFolder = " public "
2626
27+ private enum WebViewLoadingState {
28+ case unloaded
29+ case initialLoad( isOpaque: Bool )
30+ case subsequentLoad
31+ }
32+ private var webViewLoadingState = WebViewLoadingState . unloaded
33+
2734 private var isStatusBarVisible = true
2835 private var statusBarStyle : UIStatusBarStyle = . default
2936 private var statusBarAnimation : UIStatusBarAnimation = . slide
@@ -97,7 +104,12 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
97104 if let backgroundColor = ( bridge!. config. getValue ( " ios.backgroundColor " ) as? String ) ?? ( bridge!. config. getValue ( " backgroundColor " ) as? String ) {
98105 webView? . backgroundColor = UIColor ( fromHex: backgroundColor)
99106 webView? . scrollView. backgroundColor = UIColor ( fromHex: backgroundColor)
107+ } else if #available( iOS 13 , * ) {
108+ // Use the system background colors if background is not set by user
109+ webView? . backgroundColor = UIColor . systemBackground
110+ webView? . scrollView. backgroundColor = UIColor . systemBackground
100111 }
112+
101113 if let overrideUserAgent = ( bridge!. config. getValue ( " ios.overrideUserAgent " ) as? String ) ?? ( bridge!. config. getValue ( " overrideUserAgent " ) as? String ) {
102114 webView? . customUserAgent = overrideUserAgent
103115 }
@@ -173,6 +185,16 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
173185 }
174186
175187 func loadWebView( ) {
188+ // Set the webview to be not opaque on the inital load. This prevents
189+ // the webview from showing a white background, which is its default
190+ // loading display, as that can appear as a screen flash. This might
191+ // have already been set by something else, like a plugin, so we want
192+ // to save the current value to reset it on success or failure.
193+ if let webView = webView, case . unloaded = webViewLoadingState {
194+ webViewLoadingState = . initialLoad( isOpaque: webView. isOpaque)
195+ webView. isOpaque = false
196+ }
197+
176198 let fullStartPath = URL ( fileURLWithPath: assetsFolder) . appendingPathComponent ( startDir) . appendingPathComponent ( " index " )
177199 if Bundle . main. path ( forResource: fullStartPath. relativePath, ofType: " html " ) == nil {
178200 fatalLoadError ( )
@@ -298,10 +320,18 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
298320 }
299321
300322 public func webView( _ webView: WKWebView , didFinish navigation: WKNavigation ! ) {
323+ if case . initialLoad( let isOpaque) = webViewLoadingState {
324+ webView. isOpaque = isOpaque
325+ webViewLoadingState = . subsequentLoad
326+ }
301327 CAPLog . print ( " ⚡️ WebView loaded " )
302328 }
303329
304330 public func webView( _ webView: WKWebView , didFail navigation: WKNavigation ! , withError error: Error ) {
331+ if case . initialLoad( let isOpaque) = webViewLoadingState {
332+ webView. isOpaque = isOpaque
333+ webViewLoadingState = . subsequentLoad
334+ }
305335 CAPLog . print ( " ⚡️ WebView failed to load " )
306336 CAPLog . print ( " ⚡️ Error: " + error. localizedDescription)
307337 }
0 commit comments