Skip to content

Commit 9e20366

Browse files
graycreateclaude
andcommitted
fix: hide WebView until theme is applied to prevent white flash
Changed approach to completely eliminate white flash in dark mode: - Set WebView to INVISIBLE before loading - Apply theme via JavaScript when page finishes loading - Show WebView after 100ms delay to ensure JS executes - Hide loading indicator when WebView becomes visible This ensures users only see the WebView after the correct theme has been fully applied, completely eliminating the white flash that occurred during page load in dark mode. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fc95159 commit 9e20366

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

app/src/main/java/me/ghui/v2er/module/vshare/VshareWebActivity.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ protected void init() {
105105

106106
@SuppressLint("SetJavaScriptEnabled")
107107
private void setupWebView() {
108+
// Hide WebView until page is fully loaded with correct theme
109+
mWebView.setVisibility(View.INVISIBLE);
110+
108111
// Set WebView background color to match theme before loading
109112
boolean isDarkMode = DarkModelUtils.isDarkMode();
110113
if (isDarkMode) {
@@ -170,14 +173,22 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
170173
@Override
171174
public void onPageFinished(WebView view, String url) {
172175
super.onPageFinished(view, url);
173-
hideLoading();
174176

175177
// Inject CSS to ensure proper theme is applied
176178
String theme = DarkModelUtils.isDarkMode() ? "dark" : "light";
177179
String js = "javascript:(function() { " +
178180
"document.documentElement.setAttribute('data-theme', '" + theme + "'); " +
179181
"})()";
180182
mWebView.loadUrl(js);
183+
184+
// Show WebView after theme is applied (small delay to ensure JS executes)
185+
mWebView.postDelayed(new Runnable() {
186+
@Override
187+
public void run() {
188+
mWebView.setVisibility(View.VISIBLE);
189+
hideLoading();
190+
}
191+
}, 100);
181192
}
182193
});
183194
}

0 commit comments

Comments
 (0)