question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[android] PlatformColor does not respond to dark | light mode changes on android ?

See original GitHub issue

Description

PlatformColor on android does not pickup the correct color on theme changes as it does on IOS.

it’s worth mentioning that useColorScheme does pick up the device theme correctly.

https://user-images.githubusercontent.com/19273413/147874550-5c5650e5-4c5e-465a-b15a-897726f93a78.mp4

Version

66.4

Output of npx react-native info

System:
    OS: macOS 11.6.1
    CPU: (8) x64 Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
    Memory: 295.98 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.1 - /usr/local/bin/node
    Yarn: 1.22.15 - ~/.yarn/bin/yarn
    npm: 8.1.2 - ~/n/bin/npm
    Watchman: 2021.12.20.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0
    Android SDK:
      API Levels: 28, 29, 30, 31
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2, 31.0.0
      System Images: android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: Arctic Fox 2020.3.1 Patch 3 Arctic Fox 2020.3.1 Patch 3
    Xcode: 13.1/13A1030d - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_292 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.66.4 => 0.66.4
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

after creating a react native project.

[1] create a values-night/colors.xml and values/colors.xml inside android/app/src/main/res

[2] add both dark mode and light mode colors to both colors.xml files accordingly.

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <color name="text">#000000</color>
  <color name="background">#FFFFFF</color>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <color name="text">#FFFFFF</color>
  <color name="background">#000000</color>
</resources>

[3] rebuild the app.

[4] change your device theme from settings

observation: colors don’t react to the device theme.

[5] try changing your device theme then reloading from dev menu.

observation: colors change & respect the device theme after reload.

[6] removing uiMode from android:configChanges inside inside AndroidManifest.xml does resolve the issue however it’s performant ( the application would then be torn down and recreated with the theme change ).

Snack, code example, screenshot, or link to a repository

https://github.com/a-eid/platformColorAndroidIssue

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

1reaction
a-eidcommented, May 21, 2022

issue still exists, would love to contribute a fix with minimal assistance.

1reaction
a-eidcommented, Jan 19, 2022

PlatformColor seems to be working with wix/react-native-navigations some how but not with react native.

https://user-images.githubusercontent.com/19273413/148926040-921686bf-3a62-42c0-9dff-f3d88f11b9eb.mp4

Keep in mind that in the vid above I use only text from react native. All colors change correctly but not for the text. It requires an app reload

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can React Native's PlatformColor get colors for dark mode ...
I can't find any details on whether or not PlatformColor can access colors that aren't part of the currently selected system theme.
Read more >
Change to dark or color mode on your Android device
If light theme is on but an app is dark, it could be: Dark theme is on for the app, but not for...
Read more >
Using PlatformColor and Responding to Themes
Windows supports two unique native styling/theming behaviors: one being the dark and light theme changes and the other being adaptive brushes and system ......
Read more >
Color Reference - React Native
Components in React Native are styled using JavaScript. ... and allows you to specify which colors should be used in light or Dark...
Read more >
Color In React Native: Everything You Need to Know - Waldo
Plus, you also have access to native colors from Android and iOS. ... Now, change the light mode to dark mode using the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found