From 137a0b86113510b52cc931cc32f5b24f400115c1 Mon Sep 17 00:00:00 2001 From: Krzysztof Magiera Date: Mon, 26 Oct 2015 14:26:08 -0700 Subject: [PATCH] Kill @UIProp in favor of @ReactProp. Differential Revision: D2582624 fb-gh-sync-id: b04b4c90ee478d995968cab4364e1ab0964b6ebe --- .../com/facebook/react/uimanager/UIProp.java | 55 ------------------- .../facebook/react/uimanager/ViewManager.java | 42 +------------- .../ReactProgressBarViewManager.java | 1 - .../views/text/ReactTextViewManager.java | 2 - .../textinput/ReactTextInputManager.java | 1 - 5 files changed, 1 insertion(+), 100 deletions(-) delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/uimanager/UIProp.java diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIProp.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIProp.java deleted file mode 100644 index c209811a8..000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIProp.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -package com.facebook.react.uimanager; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Annotation which is used to mark native UI properties that are exposed to - * JS. {@link ViewManager#getNativeProps} traverses the fields of its - * subclasses and extracts the {@code UIProp} annotation data to generate the - * {@code NativeProps} map. Example: - * - * {@code - * @UIProp(UIProp.Type.BOOLEAN) public static final String PROP_FOO = "foo"; - * @UIProp(UIProp.Type.STRING) public static final String PROP_BAR = "bar"; - * } - * - * TODO(krzysztof): Kill this class once @ReactProp refactoring is done - */ -@Target(ElementType.FIELD) -@Retention(RUNTIME) -public @interface UIProp { - Type value(); - - public static enum Type { - BOOLEAN("boolean"), - NUMBER("number"), - STRING("String"), - MAP("Map"), - ARRAY("Array"), - COLOR("Color"); - - private final String mType; - - Type(String type) { - mType = type; - } - - @Override - public String toString() { - return mType; - } - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java index 9a56dfd2c..f9b5e1293 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java @@ -11,8 +11,6 @@ package com.facebook.react.uimanager; import javax.annotation.Nullable; -import java.lang.reflect.Field; -import java.util.HashMap; import java.util.Map; import android.view.View; @@ -30,8 +28,6 @@ import com.facebook.react.touch.JSResponderHandler; */ public abstract class ViewManager { - private static final Map> CLASS_PROP_CACHE = new HashMap<>(); - public final void updateProperties(T viewToUpdate, CatalystStylesDiffMap props) { Map propSetters = ViewManagersPropertyCache.getNativePropSettersForViewManagerClass(getClass()); @@ -208,42 +204,6 @@ public abstract class ViewManager { } public Map getNativeProps() { - // TODO(krzysztof): This method will just delegate to ViewManagersPropertyRegistry once - // refactoring is finished - Class cls = getClass(); - Map nativeProps = - ViewManagersPropertyCache.getNativePropsForView(cls, getShadowNodeClass()); - while (cls.getSuperclass() != null) { - Map props = getNativePropsForClass(cls); - for (Map.Entry entry : props.entrySet()) { - nativeProps.put(entry.getKey(), entry.getValue().toString()); - } - cls = cls.getSuperclass(); - } - return nativeProps; - } - - private Map getNativePropsForClass(Class cls) { - // TODO(krzysztof): Blow up this method once refactoring is finished - Map props = CLASS_PROP_CACHE.get(cls); - if (props != null) { - return props; - } - props = new HashMap<>(); - for (Field f : cls.getDeclaredFields()) { - UIProp annotation = f.getAnnotation(UIProp.class); - if (annotation != null) { - UIProp.Type type = annotation.value(); - try { - String name = (String) f.get(this); - props.put(name, type); - } catch (IllegalAccessException e) { - throw new RuntimeException( - "UIProp " + cls.getName() + "." + f.getName() + " must be public."); - } - } - } - CLASS_PROP_CACHE.put(cls, props); - return props; + return ViewManagersPropertyCache.getNativePropsForView(getClass(), getShadowNodeClass()); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ReactProgressBarViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ReactProgressBarViewManager.java index 051bc165b..191ce191d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ReactProgressBarViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ReactProgressBarViewManager.java @@ -19,7 +19,6 @@ import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.uimanager.BaseViewManager; import com.facebook.react.uimanager.ReactProp; import com.facebook.react.uimanager.ThemedReactContext; -import com.facebook.react.uimanager.UIProp; /** * Manages instances of ProgressBar. ProgressBar is wrapped in a FrameLayout because the style of diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java index 5021f522a..c374d4c9f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java @@ -19,11 +19,9 @@ import android.widget.TextView; import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.uimanager.BaseViewManager; -import com.facebook.react.uimanager.CatalystStylesDiffMap; import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.ReactProp; import com.facebook.react.uimanager.ThemedReactContext; -import com.facebook.react.uimanager.UIProp; import com.facebook.react.uimanager.ViewDefaults; import com.facebook.react.uimanager.ViewProps; import com.facebook.react.common.annotations.VisibleForTesting; diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index e7c28d556..00b6dfb7b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -35,7 +35,6 @@ import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.ReactProp; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.UIManagerModule; -import com.facebook.react.uimanager.UIProp; import com.facebook.react.uimanager.ViewDefaults; import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.events.EventDispatcher;