Skip to content

Commit

Permalink
Bugfix WebView showing gray background while loading content
Browse files Browse the repository at this point in the history
  • Loading branch information
Filippo committed Oct 22, 2024
1 parent 552907a commit 4b11c49
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 3 additions & 6 deletions firefox-ios/Client/TabManagement/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,6 @@ class Tab: NSObject, ThemeApplicable, FeatureFlaggable {
guard nightMode != oldValue else { return }

webView?.evaluateJavascriptInDefaultContentWorld("window.__firefox__.NightMode.setEnabled(\(nightMode))")
// For WKWebView background color to take effect, isOpaque must be false,
// which is counter-intuitive. Default is true. The color is previously
// set to black in the WKWebView init.
webView?.isOpaque = !nightMode

UserScriptManager.shared.injectUserScriptsIntoWebView(
webView,
Expand Down Expand Up @@ -532,8 +528,9 @@ class Tab: NSObject, ThemeApplicable, FeatureFlaggable {
webView.isInspectable = true
}

// Night mode enables this by toggling WKWebView.isOpaque, otherwise this has no effect.
webView.backgroundColor = .black
// Set Opaque as false to customize background color for web view
webView.isOpaque = false
webView.backgroundColor = nightMode ? .black : .clear

// Turning off masking allows the web content to flow outside of the scrollView's frame
// which allows the content appear beneath the toolbars in the BrowserViewController
Expand Down
4 changes: 4 additions & 0 deletions firefox-ios/Client/TabManagement/TabManagerNavDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class TabManagerNavDelegate: NSObject, WKNavigationDelegate {
}

func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
// restore webView content background color to default
webView.evaluateJavascriptInDefaultContentWorld("document.body.style.backgroundColor = '';")
for delegate in delegates {
delegate.webView?(webView, didCommit: navigation)
}
Expand Down Expand Up @@ -77,6 +79,8 @@ class TabManagerNavDelegate: NSObject, WKNavigationDelegate {
}

func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
// Set webView content background to transparent so that WKCompositingView doesn't show gray background while loading
webView.evaluateJavascriptInDefaultContentWorld("document.body.style.backgroundColor = 'transparent';")
for delegate in delegates {
delegate.webView?(webView, didStartProvisionalNavigation: navigation)
}
Expand Down

0 comments on commit 4b11c49

Please sign in to comment.