Creating Android views
Custom Android views can be exposed by extending SimpleViewManager, implementing a createViewInstance and getName methods, and exporting properties with the @UIProp annotation. Then a simple JavaScript file connects the dots.
public class MyCustomViewManager extends SimpleViewManager<MyCustomView> {
-
- private static final String REACT_CLASS = "MyCustomView";
-
- @UIProp(UIProp.Type.STRING)
- public static final String PROP_MY_CUSTOM_PROPERTY = "myCustomProperty";
-
@Override
public String getName() {
- return REACT_CLASS;
+ return "MyCustomView";
}
@Override
@@ -210,13 +204,9 @@ public class MyCustomViewManager extends <
return new MyCustomView(reactContext);
}
- @Override
- public void updateView(MyCustomView view, ReactStylesDiffMap props) {
- super.updateView(view, props);
-
- if (props.hasKey(PROP_MY_CUSTOM_PROPERTY)) {
- view.setMyCustomProperty(props.getString(PROP_MY_CUSTOM_PROPERTY));
- }
+ @ReactProp(name = "myCustomProperty")
+ public void setMyCustomProperty(MyCustomView view, String value) {
+ view.setMyCustomProperty(value);
}
}