From 237ee2ddf61b0e986a44cae8a3398071501b7d47 Mon Sep 17 00:00:00 2001 From: Philipp von Weitershausen Date: Fri, 13 Jan 2017 20:23:35 -0800 Subject: [PATCH] Fix Android startup exception Summary: This is an attempt to fix the following startup exception that I get when running any of the example apps: > Unrecognized type: interface com.facebook.react.bridge.Dynamic for method: com.facebook.react.uimanager.LayoutShadowNode#setFlexBasis I really have no idea what I'm doing here, just trying to get UIExplorer to compile and run so I can test my upcoming PRs. ~~Unfortunately, this doesn't actually make the apps run, but at least it does get rid of the startup exception!~~ Edit: it works now. **Test plan:** Run Movies and UIExplorer example app Closes https://github.com/facebook/react-native/pull/11896 Differential Revision: D4418927 Pulled By: mkonicek fbshipit-source-id: 34788b790b6bfc46ff39a0d9ca1698a5c20662e1 --- .../uimanager/ViewManagersPropertyCache.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java index 063c999da..43d2509de 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagersPropertyCache.java @@ -12,6 +12,7 @@ import java.util.Map; import android.view.View; import com.facebook.common.logging.FLog; +import com.facebook.react.bridge.Dynamic; import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; @@ -114,6 +115,22 @@ import com.facebook.react.uimanager.annotations.ReactPropGroup; protected abstract @Nullable Object extractProperty(ReactStylesDiffMap props); } + private static class DynamicPropSetter extends PropSetter { + + public DynamicPropSetter(ReactProp prop, Method setter) { + super(prop, "mixed", setter); + } + + public DynamicPropSetter(ReactPropGroup prop, Method setter, int index) { + super(prop, "mixed", setter, index); + } + + @Override + protected Object extractProperty(ReactStylesDiffMap props) { + return props.getDynamic(mPropName); + } + } + private static class IntPropSetter extends PropSetter { private final int mDefaultValue; @@ -331,7 +348,9 @@ import com.facebook.react.uimanager.annotations.ReactPropGroup; ReactProp annotation, Method method, Class propTypeClass) { - if (propTypeClass == boolean.class) { + if (propTypeClass == Dynamic.class) { + return new DynamicPropSetter(annotation, method); + } else if (propTypeClass == boolean.class) { return new BooleanPropSetter(annotation, method, annotation.defaultBoolean()); } else if (propTypeClass == int.class) { return new IntPropSetter(annotation, method, annotation.defaultInt()); @@ -361,7 +380,13 @@ import com.facebook.react.uimanager.annotations.ReactPropGroup; Class propTypeClass, Map props) { String[] names = annotation.names(); - if (propTypeClass == int.class) { + if (propTypeClass == Dynamic.class) { + for (int i = 0; i < names.length; i++) { + props.put( + names[i], + new DynamicPropSetter(annotation, method, i)); + } + } else if (propTypeClass == int.class) { for (int i = 0; i < names.length; i++) { props.put( names[i],