Kill @UIProp in favor of @ReactProp.

Differential Revision: D2582624

fb-gh-sync-id: b04b4c90ee478d995968cab4364e1ab0964b6ebe
This commit is contained in:
Krzysztof Magiera 2015-10-26 14:26:08 -07:00 committed by facebook-github-bot-9
parent 6a7567e742
commit 137a0b8611
5 changed files with 1 additions and 100 deletions

View File

@ -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;
}
}
}

View File

@ -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<T extends View, C extends ReactShadowNode> {
private static final Map<Class, Map<String, UIProp.Type>> CLASS_PROP_CACHE = new HashMap<>();
public final void updateProperties(T viewToUpdate, CatalystStylesDiffMap props) {
Map<String, ViewManagersPropertyCache.PropSetter> propSetters =
ViewManagersPropertyCache.getNativePropSettersForViewManagerClass(getClass());
@ -208,42 +204,6 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode> {
}
public Map<String, String> getNativeProps() {
// TODO(krzysztof): This method will just delegate to ViewManagersPropertyRegistry once
// refactoring is finished
Class cls = getClass();
Map<String, String> nativeProps =
ViewManagersPropertyCache.getNativePropsForView(cls, getShadowNodeClass());
while (cls.getSuperclass() != null) {
Map<String, UIProp.Type> props = getNativePropsForClass(cls);
for (Map.Entry<String, UIProp.Type> entry : props.entrySet()) {
nativeProps.put(entry.getKey(), entry.getValue().toString());
}
cls = cls.getSuperclass();
}
return nativeProps;
}
private Map<String, UIProp.Type> getNativePropsForClass(Class cls) {
// TODO(krzysztof): Blow up this method once refactoring is finished
Map<String, UIProp.Type> 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());
}
}

View File

@ -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

View File

@ -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;

View File

@ -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;