-
Notifications
You must be signed in to change notification settings - Fork 583
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
Plugin to enable prefers-color-scheme on all platforms by enabling it in android #1010
Comments
if this is the case what else is required? Does it only work with a certain version of capacitor and above? I no longer see: |
It only works if you have the WebView up to date, don’t remember in which version chrome team implemented it, I think it was around version 90. |
OK thanks I did however test the new capacitor solution with simulator on API 30 and it wasn't working there either We have one tester with an android device that did pickup support, but that was prior to me even finding our fix and at the time didn't have your recommended either. I was suspecting it also has to do with the actual webView version as you also suggest. |
I can confirm that the media query + theme change is not working consistently. |
Dark mode and WebView version comments: Daily driver, Xiami with MIUI ( :/ ) always worked (and had webview v104.0.5112.69 but unsure since when) My samsung android 9 tablet doesn't work, has v74.0.3729.136 but the bigger problem there is Settings|Apps states that WebView is Disabled and I can't figure out how to enable it (does not obey adb shell "pm enable com.google.android.webview", the enable button is disabled in Settings… :P ) |
Hey folks, don't beat your head over this. Just use my dark mode plugin. Guaranteed to work on any Android system that supports dark mode, and supports user dark mode setting on all systems. |
aparajita, saying "guaranteed" seems very optimistic to me 😄 , but I can confirm your plugin worked at first try in my ionic6+angular14+capacitor4 app both web, android and ios!
app.component.ts:
💥 worked in web, ios and android (even on the tricky old samsung android 9 with unInstallable Webview 🥳 ) |
It is guaranteed to work on any system that supports dark mode because I'm getting the current mode directly from the system and not relying on WebView working correctly. |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out. |
Feature Request
The following can solve darkmode detection etc on android by simply making prefers-color-scheme work.
There is no need for an abstracted api because:
@media (prefers-color-scheme: dark)
andwindow.matchMedia('(prefers-color-scheme: dark)')
already work perfectly fine in web and iOS.Thus all the plugin needs to do is enable it in android and usage cann all be done via css media queries and/or matchMedia events
Plugin
Enables prefers-color-scheme detection in android's webView.
I have actuallly worked all this out in our app in the
MainActivity.java
.I've created this issue to:
What I mean by this is:
A typical plugin would have a js api interface but this one doesnt need one because it just makes is so you can use prefers-color-scheme queries consistently everywhere.
Description
This relates to requests for darkmode support.
I found that none of the current community plugins fully support it and some dont install as they havent been maintained.
Regardless, they also abstract something that doesnt need to be abstracted. You can simply use css media queries or matchMedia to handle color scheme changes.
In our app we use
window.matchMedia('(prefers-color-scheme: dark)')
to detect scheme changesThis works consistently on iOS, web and now Android with the proposed plugin code.
My criteria of this to match iOS and web behaviour was it must:
Platform(s)
Android - makes prefers-color-scheme work as expected
Preferred Solution
Enable prefers-color-scheme and matchmedia events by:
adding the required check onResume and onConfigurationChanged in android and forcing darkmode when appropriate using the feature that forces via the webViews prefers-color-scheme media
Nothing is required for iOS or Web
Documentation would guide user to simply use media queries and matchMedia as per w3c spec to handle darkmode needs.
Alternatives
Additional Context
The text was updated successfully, but these errors were encountered: