Add annotation processor for @ReactProp

Summary:
The annotation processor finds subclasses of ViewManager and ShadowNode and generates classes that can both provide a mapping of property names to their type as well as a way of setting these properties.

This avoids having to do reflection to find the properties.

The annotation processor is currently not working when building with Gradle.

public

Reviewed By: astreet

Differential Revision: D2748958

fb-gh-sync-id: ded5b072d236ebf19fb43eaf704fc7f221a82c26
This commit is contained in:
Alexander Blom
2016-01-07 03:51:28 -08:00
committed by facebook-github-bot-4
parent c1b7a369af
commit 57f6cbb3dc
8 changed files with 880 additions and 37 deletions

View File

@@ -16,32 +16,22 @@ import java.util.Map;
import android.view.View;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.touch.CatalystInterceptingViewGroup;
import com.facebook.react.touch.JSResponderHandler;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.annotations.ReactPropGroup;
import com.facebook.react.uimanager.annotations.ReactPropertyHolder;
/**
* Class responsible for knowing how to create and update catalyst Views of a given type. It is also
* responsible for creating and updating CSSNode subclasses used for calculating position and size
* for the corresponding native view.
*/
@ReactPropertyHolder
public abstract class ViewManager<T extends View, C extends ReactShadowNode> {
public final void updateProperties(T viewToUpdate, CatalystStylesDiffMap props) {
Map<String, ViewManagersPropertyCache.PropSetter> propSetters =
ViewManagersPropertyCache.getNativePropSettersForViewManagerClass(getClass());
ReadableMap propMap = props.mBackingMap;
ReadableMapKeySetIterator iterator = propMap.keySetIterator();
while (iterator.hasNextKey()) {
String key = iterator.nextKey();
ViewManagersPropertyCache.PropSetter setter = propSetters.get(key);
if (setter != null) {
setter.updateViewProp(this, viewToUpdate, props);
}
}
ViewManagerPropertyUpdater.updateProps(this, viewToUpdate, props);
onAfterUpdateTransaction(viewToUpdate);
}
@@ -206,6 +196,6 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode> {
}
public Map<String, String> getNativeProps() {
return ViewManagersPropertyCache.getNativePropsForView(getClass(), getShadowNodeClass());
return ViewManagerPropertyUpdater.getNativeProps(getClass(), getShadowNodeClass());
}
}