Skip to content

fix(ui): initialize WebView background from system night mode to prevent first-paint flash - #363

Open
TimeToBuildBob wants to merge 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix/dark-first-paint
Open

TimeToBuildBob wants to merge 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix/dark-first-paint

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Problem

Startup and fresh drawer navigation (Activity, Raw Data, Dashboard Settings) show a white flash in dark mode. The reporter on #300 confirmed this after #301 fixed theme selection.

Root cause: WebUIFragment.onCreateView() creates the WebView with its default white background. The JS theme hook (ANDROID_THEME_HOOK_JS) only sets the correct colour after onPageFinished, leaving the white surface visible for the entire page-load window.

Fix

Set myWebView.setBackgroundColor() immediately at WebView creation using the system night mode as the pre-load approximation. The existing JS hook still corrects the colour after onPageFinished reads localStorage.theme, so explicit Light and Dark overrides are unaffected.

Introduces initialWebViewBackgroundRes() in WebUiTheme.kt — a pure function that maps Configuration.UI_MODE_NIGHT_YES/NO → R.color.chrome_dark/chrome_light, tested in WebUiThemeTest.

Testing

Closes #300 (pending device verification)

…ent first-paint flash

Before this change, WebUIFragment created its WebView with the default
white background. The JS theme hook (ANDROID_THEME_HOOK_JS) only set
the correct colour after onPageFinished, leaving a white flash visible
during startup and each fresh drawer navigation in dark mode.

Set the background immediately at WebView creation using the system night
mode as the pre-load approximation. The JS hook still corrects it after
onPageFinished reads localStorage.theme, so explicit Light/Dark overrides
are unaffected.

Introduces initialWebViewBackgroundRes() in WebUiTheme — a pure function
that picks chrome_dark or chrome_light based on Configuration.uiMode,
tested in WebUiThemeTest.

Closes ActivityWatch#300 (pending device verification — see issue)

Git-Session-Id: 67c1dcbe-e031-4889-8f5c-3f7071249702
@greptile-apps

greptile-apps Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Low impact] This PR appears safe to merge; no actionable issues introduced by the change were found.

Summary

Sets the WebView background before loading the page, using the system night mode to avoid a white first frame on dark devices.

  • WebViews start with a background that matches system night mode.

Intent acknowledged: TimeToBuildBob describes the system-based starting color as a pre-load approximation. A saved theme that differs from the system can still change the color after loading; this is intentional.
Validation: code review only; tests and device checks were not run.

Reviews (1) · Last reviewed commit: "fix(ui): initialize WebView background f..." · Reviewed by Greptile

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Greptile found no actionable issues on 5027043 (5/5). Unit tests and the release-variant R8 smoke check passed; E2E is still running. No code change or review retrigger is needed for this notification.

This only initializes the blank WebView surface. It does not verify the document's first painted frame or eliminate a saved-theme/system-theme mismatch during loading. #300 stays open until startup and drawer navigation are verified in an Android build with System dark/light and explicit Light/Dark controls; this PR still needs maintainer review/merge.

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click.

This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted.

@TimeToBuildBob

TimeToBuildBob commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 AI code review

Adds initialWebViewBackgroundRes() in WebUiTheme.kt to map system night mode to chrome_dark/chrome_light, and calls setBackgroundColor() in WebUIFragment.onCreateView() before the page loads to avoid a white flash. Adds a unit test for the new function.

Safe to merge — no P0/P1 findings

Confidence 5/5

✅ No findings. The diff looks correct to me on this pass.

Files changed (3) — the diff as I read it
  • mobile/src/main/java/net/activitywatch/android/WebUiTheme.kt — Adds initialWebViewBackgroundRes() that returns chrome_dark or chrome_light based on system night mode.
  • mobile/src/main/java/net/activitywatch/android/fragments/WebUIFragment.kt — Sets the WebView background color immediately at creation using the new initialWebViewBackgroundRes() function.
  • mobile/src/test/java/net/activitywatch/android/WebUiThemeTest.kt — Adds a test verifying initialWebViewBackgroundRes() follows system night mode.

Reviewed 5027043a47ea · openrouter/deepseek/deepseek-v4-flash-0731 · llm engine · 18s · about this reviewer

Maintainer commands

@TimeToBuildBob review (own line) — fresh review · @TimeToBuildBob fix — a worker acts on the findings. Once per comment; 👀 = received.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App fails to follow system theme and falls back to light theme

1 participant