From 61ebbda34f9becb975c2f442d99d0585515d0609 Mon Sep 17 00:00:00 2001 From: Ivan Alexandrov Date: Wed, 11 Oct 2023 08:47:23 -0700 Subject: [PATCH] Fix android platform border color (#39893) Summary: If you try to apply PlatformColor to borders on Android app will crash with the next error: "Error while updating property 'borderColor' of a view managed by: RCTView" ## Changelog: [ANDROID] [FIXED] - Fix android crash when apply PlatformColor to borders Pull Request resolved: https://github.com/facebook/react-native/pull/39893 Test Plan: In RNTester example, go to APIs -> PlatformColor | Before | After | | ----------- | ----------- | | drawing | drawing | Reviewed By: NickGerleman Differential Revision: D50011758 Pulled By: javache fbshipit-source-id: ea06c18c6aef4b6731e9b9b87422a1e0d13de208 (cherry picked from commit 265af222aa8acb3b514e22a7db191d66755f553b) --- .../uimanager/ViewManagersPropertyCache.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java index 438ec3fd0b57c6..9cbb6d11731fa6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java @@ -204,6 +204,11 @@ public ColorPropSetter(ReactProp prop, Method setter, int defaultValue) { mDefaultValue = defaultValue; } + public ColorPropSetter(ReactPropGroup prop, Method setter, int index, int defaultValue) { + super(prop, "mixed", setter, index); + mDefaultValue = defaultValue; + } + @Override protected Object getValueOrDefault(Object value, Context context) { if (value == null) { @@ -331,6 +336,10 @@ public BoxedColorPropSetter(ReactProp prop, Method setter) { super(prop, "mixed", setter); } + public BoxedColorPropSetter(ReactPropGroup prop, Method setter, int index) { + super(prop, "mixed", setter, index); + } + @Override protected @Nullable Object getValueOrDefault(Object value, Context context) { if (value != null) { @@ -463,7 +472,11 @@ private static void createPropSetters( } } else if (propTypeClass == int.class) { for (int i = 0; i < names.length; i++) { - props.put(names[i], new IntPropSetter(annotation, method, i, annotation.defaultInt())); + if ("Color".equals(annotation.customType())) { + props.put(names[i], new ColorPropSetter(annotation, method, i, annotation.defaultInt())); + } else { + props.put(names[i], new IntPropSetter(annotation, method, i, annotation.defaultInt())); + } } } else if (propTypeClass == float.class) { for (int i = 0; i < names.length; i++) { @@ -476,7 +489,11 @@ private static void createPropSetters( } } else if (propTypeClass == Integer.class) { for (int i = 0; i < names.length; i++) { - props.put(names[i], new BoxedIntPropSetter(annotation, method, i)); + if ("Color".equals(annotation.customType())) { + props.put(names[i], new BoxedColorPropSetter(annotation, method, i)); + } else { + props.put(names[i], new BoxedIntPropSetter(annotation, method, i)); + } } } else { throw new RuntimeException(