From 2cc8acf2e3734397eb2b732e8219a18e8d0ebb6f Mon Sep 17 00:00:00 2001 From: Aaron Chiu Date: Wed, 30 Sep 2015 20:56:59 -0700 Subject: [PATCH] enabled border width and border color (sync diff 2) Differential Revision: D2497575 --- .../react/views/image/ReactImageManager.java | 14 ++++++++++++++ .../react/views/image/ReactImageView.java | 19 +++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java index e9d35d8a0..429348b79 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java @@ -58,6 +58,20 @@ public class ReactImageManager extends SimpleViewManager { public void setSource(ReactImageView view, @Nullable String source) { view.setSource(source); } + + @ReactProp(name = "borderColor", customType = "Color") + public void setBorderColor(ReactImageView view, @Nullable Integer borderColor) { + if (borderColor == null) { + view.setBorderColor(Color.TRANSPARENT); + } else { + view.setBorderColor(borderColor); + } + } + + @ReactProp(name = "borderWidth") + public void setBorderWidth(ReactImageView view, float borderWidth) { + view.setBorderWidth(borderWidth); + } @ReactProp(name = "borderRadius") public void setBorderRadius(ReactImageView view, float borderRadius) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java index 6253ea853..14995c3e1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java @@ -22,12 +22,9 @@ import android.graphics.RectF; import android.graphics.Shader; import android.net.Uri; +import com.facebook.common.util.UriUtil; import com.facebook.drawee.controller.AbstractDraweeControllerBuilder; import com.facebook.drawee.controller.ControllerListener; -import com.facebook.react.uimanager.PixelUtil; -import com.facebook.common.util.UriUtil; -import com.facebook.drawee.backends.pipeline.Fresco; -import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder; import com.facebook.drawee.drawable.ScalingUtils; import com.facebook.drawee.generic.GenericDraweeHierarchy; import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; @@ -39,6 +36,7 @@ import com.facebook.imagepipeline.request.BasePostprocessor; import com.facebook.imagepipeline.request.ImageRequest; import com.facebook.imagepipeline.request.ImageRequestBuilder; import com.facebook.imagepipeline.request.Postprocessor; +import com.facebook.react.uimanager.PixelUtil; /** * Wrapper class around Fresco's GenericDraweeView, enabling persisting props across multiple view @@ -99,6 +97,8 @@ public class ReactImageView extends GenericDraweeView { } private @Nullable Uri mUri; + private int mBorderColor; + private float mBorderWidth; private float mBorderRadius; private ScalingUtils.ScaleType mScaleType; private boolean mIsDirty; @@ -127,6 +127,16 @@ public class ReactImageView extends GenericDraweeView { mCallerContext = callerContext; } + public void setBorderColor(int borderColor) { + mBorderColor = borderColor; + mIsDirty = true; + } + + public void setBorderWidth(float borderWidth) { + mBorderWidth = PixelUtil.toPixelFromDIP(borderWidth); + mIsDirty = true; + } + public void setBorderRadius(float borderRadius) { mBorderRadius = PixelUtil.toPixelFromDIP(borderRadius); mIsDirty = true; @@ -180,6 +190,7 @@ public class ReactImageView extends GenericDraweeView { RoundingParams roundingParams = hierarchy.getRoundingParams(); roundingParams.setCornersRadius(hierarchyRadius); + roundingParams.setBorder(mBorderColor, mBorderWidth); hierarchy.setRoundingParams(roundingParams); hierarchy.setFadeDuration(mImageFadeDuration >= 0 ? mImageFadeDuration