Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for Dark Mode #51

Merged
merged 1 commit into from
Jan 3, 2020

Conversation

andreban
Copy link
Member

@andreban andreban commented Jan 3, 2020

  • Supports selecting a dark mode color for the status bar and the
    navigation bar.

Closes #50

- Supports selecting a dark mode color for the status bar and the
  navigation bar.
@andreban andreban requested a review from PEConn January 3, 2020 12:55
@andreban andreban merged commit 5a0accd into GoogleChrome:master Jan 3, 2020
@khmyznikov
Copy link

Can you do the same for SPLASH_SCREEN_BACKGROUND_COLOR?

@andreban
Copy link
Member Author

andreban commented Jan 7, 2020

I think this one requires a change beyond this library. @PEConn can confirm.

@PEConn
Copy link
Contributor

PEConn commented Jan 8, 2020

So while things like navbar theme colours need to be passed over to the browser, the splash screen colour is used to create a splash screen (in the TWA) and then handed over to the browser. Luckily however, the splashscreen is only relevant for a short amount of time so we could just add logic like this in LauncherActivity (around line 131):

if (mode = LIGHT) {
  splashScreenColor = lightSplashColor;
} else {
  splashScreenColor = darkSplashColor;
}

@andreban andreban deleted the dark-mode-support branch January 9, 2020 08:02
@andreban
Copy link
Member Author

andreban commented Jan 9, 2020

@PEConn is right. We may be able to override the colour using qualified resources on Android. Will check if it's possible and update.

@khmyznikov
Copy link

So what's about splash screen color?

@uwolfer
Copy link

uwolfer commented Mar 5, 2024

I added dark mode to a PWA bundled with bubblewrap, including splash screen. The changes were quite simple - but took some time to get into it. Sharing here the key changes I did - probably it helps somebody else:

  1. copied all res/drawable folders to res/drawable-night-*, and adjusted splash.png
  2. added res/values-night/colors.xml which defined the backgroundColor: <color name="backgroundColor">#000000</color>
  3. adjusted my LauncherActivity.java with an ugly workaround because of a bug in android-browser-helper as follows:
+import android.content.SharedPreferences;
 import android.content.pm.ActivityInfo;
 import android.net.Uri;
 import android.os.Build;
@@ -30,6 +31,10 @@
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
+        // workaround for this bug: https://github.com/GoogleChrome/android-browser-helper/issues/461
+        SharedPreferences splashImagePrefs = this.getApplicationContext().getApplicationContext().getSharedPreferences("splashImagePrefs", 0);
+        splashImagePrefs.edit().remove("lastUpdateTime").apply();
+
         super.onCreate(savedInstanceState);

@khmyznikov
Copy link

@uwolfer this is so cool! Do you considered to contribute into bubblewrap with this fix?

@uwolfer
Copy link

uwolfer commented Mar 6, 2024

@khmyznikov IMO my change is not really a fix, but more an ugly workaround, which prevents caching of the splash screen. I would like to get this properly fixed in android-browser-helper: #461
I am quite sure where the underlying issue is, and tried to describe it. If you have any connections at Chrome / android-browser-helper, it would be nice if you could get them to look into the issue. Once that is fixed, we could think about improving dark mode in bubblewrap, as there are really only a few changes required, and most of the work is generating proper splash images.

@khmyznikov
Copy link

@uwolfer how bad is caching prevention for splash? Is it leading to what?

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.

Add Dark Mode support
4 participants