From 265af222aa8acb3b514e22a7db191d66755f553b 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 --- .../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 c187cac7bea303..09ae7a272ad0e6 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) { @@ -468,7 +477,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++) { @@ -481,7 +494,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(