From ec104e9fba68e0c31778f916da69765c8eec03f1 Mon Sep 17 00:00:00 2001 From: Krzysztof Magiera Date: Wed, 28 Oct 2015 20:37:14 +0000 Subject: [PATCH] Docs for @ReactProp --- docs/NativeComponentsAndroid.md | 35 ++++++--------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/docs/NativeComponentsAndroid.md b/docs/NativeComponentsAndroid.md index fed4d634e..41402357c 100644 --- a/docs/NativeComponentsAndroid.md +++ b/docs/NativeComponentsAndroid.md @@ -67,44 +67,21 @@ Setter declaration requirements for methods annotated with `@ReactPropGroup` are ```java @ReactProp(name = "src") - public void setSrc(ReactImageView view, String src) { + public void setSrc(ReactImageView view, @Nullable String src) { + view.setSource(src); } - @ReactProp(name = "borderRadius") + @ReactProp(name = "borderRadius", defaultFLoat = 0f) public void setBorderRadius(ReactImageView view, float borderRadius) { + view.setBorderRadius(borderRadius); } - @ReactProp(name = ViewProps.RESIZE_MODE) - public void setResizeMode(ReactImageView view, String resizeMode) { + public void setResizeMode(ReactImageView view, @Nullable String resizeMode) { + view.setScaleType(ImageResizeMode.toScaleType(resizeMode)); } ``` -## 4. Implement method `updateView` - -Setting properties on a view is not handled by automatically calling setter methods as it is on iOS; for Android, you manually invoke the setters via the `updateView` of your `ViewManager`. Values are fetched from the `CatalystStylesDiffMap` and dispatched to the `View` instance as required. It is up to a combination of `updateView` and the `View` class to check the validity of the properties and behave accordingly. - -```java - @Override - public void updateView(final ReactImageView view, - final CatalystStylesDiffMap props) { - super.updateView(view, props); - - if (props.hasKey(PROP_RESIZE_MODE)) { - view.setScaleType( - ImageResizeMode.toScaleType(props.getString(PROP_RESIZE_MODE))); - } - if (props.hasKey(PROP_SRC)) { - view.setSource(props.getString(PROP_SRC)); - } - if (props.hasKey(PROP_BORDER_RADIUS)) { - view.setBorderRadius(props.getFloat(PROP_BORDER_RADIUS, 0.0f)); - } - view.maybeUpdateView(); - } -} -``` - ## 5. Register the `ViewManager` The final Java step is to register the ViewManager to the application, this happens in a similar way to [Native Modules](NativeModulesAndroid.md), via the applications package member function `createViewManagers.`