-
Notifications
You must be signed in to change notification settings - Fork 25k
Add Platform.nightMode for Android
#24790
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
Conversation
|
Also need to update docs, Can you post a PR to https://github.com/facebook/react-native-website too. |
|
@gengjiawen thank you! Submitted (and referenced above). |
|
@turnrye Can you rebase this PR, seems Circle CI not triggered. |
|
Multiple platforms (web, macOS) already support dark modes too. The web API is a new media-query If we were to follow that path, we'd have an API more like |
|
we should have a listener pattern here instead, since dark/night mode can change on the fly, which should cause a re-render. |
|
We had a conversation about this at FB and the conclusion seems to be that this shouldn't be part of Platform because it isn't tied to the platform but rather a user setting that can change at anytime, unlike Platform. My suggestion would be to make this a third-party native module first, and consider it for inclusion to React Native later. |
This is going to be a very common feature to support, including at FB, so it might be worth getting ahead of the API design churn and suggesting something ourselves soon. |
|
I'm fine considering this for inclusion into core if people agree but we should discuss a proposal in https://github.com/react-native-community/discussions-and-proposals first. |
Summary
Android Q is raising Dark Mode to prominence across the ecosystem. One of the expectations is to be able to respond to the system-wide dark theme setting. I've followed their documentation, added the flag to the InfoModule, and then presented this value to the RN user space via an Android-specific Platform value
nightMode. There are rumors that similar functionality may come soon for iOS, and we may want to consider refactoring the JS side at that point for consistency between the two platforms.Changelog
[Android] [Added] - Add ability to check what system preference is set for dark mode
Test Plan
I added
Platform.nightModeto a sample app and saw it get "yes" and "no" based off of whether I'd selected light theme or dark theme on the Q beta.