@@ -24,6 +24,13 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
24
24
private var basePath : String = " "
25
25
private let assetsFolder = " public "
26
26
27
+ private enum WebViewLoadingState {
28
+ case unloaded
29
+ case initialLoad( isOpaque: Bool )
30
+ case subsequentLoad
31
+ }
32
+ private var webViewLoadingState = WebViewLoadingState . unloaded
33
+
27
34
private var isStatusBarVisible = true
28
35
private var statusBarStyle : UIStatusBarStyle = . default
29
36
private var statusBarAnimation : UIStatusBarAnimation = . slide
@@ -97,7 +104,12 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
97
104
if let backgroundColor = ( bridge!. config. getValue ( " ios.backgroundColor " ) as? String ) ?? ( bridge!. config. getValue ( " backgroundColor " ) as? String ) {
98
105
webView? . backgroundColor = UIColor ( fromHex: backgroundColor)
99
106
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
100
111
}
112
+
101
113
if let overrideUserAgent = ( bridge!. config. getValue ( " ios.overrideUserAgent " ) as? String ) ?? ( bridge!. config. getValue ( " overrideUserAgent " ) as? String ) {
102
114
webView? . customUserAgent = overrideUserAgent
103
115
}
@@ -173,6 +185,16 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
173
185
}
174
186
175
187
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
+
176
198
let fullStartPath = URL ( fileURLWithPath: assetsFolder) . appendingPathComponent ( startDir) . appendingPathComponent ( " index " )
177
199
if Bundle . main. path ( forResource: fullStartPath. relativePath, ofType: " html " ) == nil {
178
200
fatalLoadError ( )
@@ -298,10 +320,18 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
298
320
}
299
321
300
322
public func webView( _ webView: WKWebView , didFinish navigation: WKNavigation ! ) {
323
+ if case . initialLoad( let isOpaque) = webViewLoadingState {
324
+ webView. isOpaque = isOpaque
325
+ webViewLoadingState = . subsequentLoad
326
+ }
301
327
CAPLog . print ( " ⚡️ WebView loaded " )
302
328
}
303
329
304
330
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
+ }
305
335
CAPLog . print ( " ⚡️ WebView failed to load " )
306
336
CAPLog . print ( " ⚡️ Error: " + error. localizedDescription)
307
337
}
0 commit comments