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.

PlatformColor does not work properly on Android

See original GitHub issue

Description

PlatformColor documentation clearly says that if I want to use the values of R.attr in Android, I have to use ?attr/VALUE, but when I use for example ?attr/textColorPrimary, the app crashes on Android or throws an error.

https://developer.android.com/reference/android/R.attr#textColorPrimary

React Native version:

System:
    OS: macOS 10.15.5
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 789.87 MB / 32.00 GB
    Shell: 5.8 - /usr/local/bin/zsh
  Binaries:
    Node: 12.14.1 - /usr/local/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.6, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 23, 26, 27, 28, 29
      Build Tools: 23.0.1, 27.0.3, 28.0.1, 28.0.3, 29.0.2
      System Images: android-25 | Google APIs ARM 64 v8a, android-25 | Google APIs ARM EABI v7a, android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
      Android NDK: 20.0.5594570
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6514223
    Xcode: 11.6/11E708 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_232 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: 0.63.2 => 0.63.2 
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

  1. Paste this into your code: <Text style={{color: PlatformColor('?attr/textColorPrimary')}}>Test</Text>
  2. Run your code on Android

Expected Results

The app should not crash.

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

image

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
hank121314commented, Mar 5, 2021

This issue seems to cause by getIdentifier("textColorPrimary", ATRR, packageName) return 0. At here: https://github.com/facebook/react-native/blob/a65cd683aee40fbb0433f43e15b8366dc1fa02a4/ReactAndroid/src/main/java/com/facebook/react/bridge/ColorPropConverter.java#L113

This needs further investigation to identify why getIdentifier("textColorPrimary", ATRR, packageName) will return 0. 😢

2reactions
sallarcommented, Aug 28, 2020

@safaiyeh exactly. If the error happens on first render, the app crashes completely and exits. I had to film the screen and slow it down to see the error because it exits so fast.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PlatformColor - React Native
You can use the PlatformColor function to access native colors on the target platform by supplying the native color's corresponding string ...
Read more >
Using PlatformColor and Responding to Themes
This article will show you how to set up your app to listen to theme changes and use the Windows brushes when and...
Read more >
React Native Tutorial 42 - PlatformColor - YouTube
Welcome to this course on React Native, React Native is used hybrid mobile app development. Facebook's React Native user interface (UI) ...
Read more >
React Native Weekly - W27 2021 - Andrei Calazans
When PlatformColor is used with backgroundColor, this line would throw, ... to allow native Android Views to be marked as “not clippable”, ...
Read more >
Five React Native tricks - Folder IT
That you don't know but you will want to use When we talk about React ... and lets you know what is to...
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