change android PlatformColor binding to use built-in selector by diaozheng999 · Pull Request #737 · rescript-react-native/rescript-react-native

Hi there,

A quick PR for the default Android PlatformColor selectors to get the system-defined values instead of app-defined values. In the default react native init app, there's no colors defined in styles.xml, so the app would get the following error when rendering using PlatformColor

2021-03-07 18:04:42.833 9614-9614/com.precisely E/unknown:ReactNative: Exception in native call
    com.facebook.react.bridge.JSApplicationIllegalArgumentException: Error while updating property 'backgroundColor' of a view managed by: RCTView
        at com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter.updateViewProp(ViewManagersPropertyCache.java:102)
        at com.facebook.react.uimanager.ViewManagerPropertyUpdater$FallbackViewManagerSetter.setProperty(ViewManagerPropertyUpdater.java:136)
        at com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps(ViewManagerPropertyUpdater.java:56)
        at com.facebook.react.uimanager.ViewManager.updateProperties(ViewManager.java:49)
        at com.facebook.react.uimanager.NativeViewHierarchyManager.createView(NativeViewHierarchyManager.java:270)
        at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute(UIViewOperationQueue.java:186)
        ...
     Caused by: com.facebook.react.bridge.JSApplicationCausedNativeException: ColorValue: None of the paths in the `resource_paths` array resolved to a color resource.
        at com.facebook.react.bridge.ColorPropConverter.getColor(ColorPropConverter.java:71)
        at com.facebook.react.uimanager.ViewManagersPropertyCache$ColorPropSetter.getValueOrDefault(ViewManagersPropertyCache.java:213)
       ...

The colors is rendered as follows (on Pixel 2 XL, Android 11, using default Theme.AppCompat.DayNight.NoActionBar):

  1. Dark Theme
    Pixel2XL_dark
  2. Light Theme
    Pixel2XL_light

I've left color as it is since both ?attr/color and ?android:attr/color generated the above error.

My only concern here is that this is a change in behaviour for anyone already using these variants to get values from application style, since they'll need to use unsafeGet to get the same behaviour.