mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-12 22:29:41 +08:00
added support for overlayColor property for image
Summary: In Android, Fresco's default rounding corners support mode is BITMAP_ONLY which doesn't work in all cases (such as animated GIF's, some scale types, etc.). Specifying the new "overlayColor" property on an Image will cause Fresco to switch to the other rounding corners mode, OVERLAY_COLOR, and will draw rounded corners by overlaying the solid color specified. Fresco's behaviour is explained here: http://frescolib.org/docs/rounded-corners-and-circles.html Closes https://github.com/facebook/react-native/pull/5366 Reviewed By: svcscm Differential Revision: D2854696 Pulled By: mkonicek fb-gh-sync-id: 251701ee8a64acbfc22694e9d4661c40eef75725
This commit is contained in:
committed by
facebook-github-bot-7
parent
099827372d
commit
f68281a0d8
@@ -88,6 +88,15 @@ public class ReactImageManager extends SimpleViewManager<ReactImageView> {
|
||||
}
|
||||
}
|
||||
|
||||
@ReactProp(name = "overlayColor")
|
||||
public void setOverlayColor(ReactImageView view, @Nullable Integer overlayColor) {
|
||||
if (overlayColor == null) {
|
||||
view.setOverlayColor(Color.TRANSPARENT);
|
||||
} else {
|
||||
view.setOverlayColor(overlayColor);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactProp(name = "borderWidth")
|
||||
public void setBorderWidth(ReactImageView view, float borderWidth) {
|
||||
view.setBorderWidth(borderWidth);
|
||||
|
||||
@@ -16,6 +16,7 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
@@ -108,6 +109,7 @@ public class ReactImageView extends GenericDraweeView {
|
||||
private @Nullable Uri mUri;
|
||||
private @Nullable Drawable mLoadingImageDrawable;
|
||||
private int mBorderColor;
|
||||
private int mOverlayColor;
|
||||
private float mBorderWidth;
|
||||
private float mBorderRadius;
|
||||
private ScalingUtils.ScaleType mScaleType;
|
||||
@@ -186,6 +188,11 @@ public class ReactImageView extends GenericDraweeView {
|
||||
mIsDirty = true;
|
||||
}
|
||||
|
||||
public void setOverlayColor(int overlayColor) {
|
||||
mOverlayColor = overlayColor;
|
||||
mIsDirty = true;
|
||||
}
|
||||
|
||||
public void setBorderWidth(float borderWidth) {
|
||||
mBorderWidth = PixelUtil.toPixelFromDIP(borderWidth);
|
||||
mIsDirty = true;
|
||||
@@ -266,6 +273,12 @@ public class ReactImageView extends GenericDraweeView {
|
||||
RoundingParams roundingParams = hierarchy.getRoundingParams();
|
||||
roundingParams.setCornersRadius(hierarchyRadius);
|
||||
roundingParams.setBorder(mBorderColor, mBorderWidth);
|
||||
if (mOverlayColor != Color.TRANSPARENT) {
|
||||
roundingParams.setOverlayColor(mOverlayColor);
|
||||
} else {
|
||||
// make sure the default rounding method is used.
|
||||
roundingParams.setRoundingMethod(RoundingParams.RoundingMethod.BITMAP_ONLY);
|
||||
}
|
||||
hierarchy.setRoundingParams(roundingParams);
|
||||
hierarchy.setFadeDuration(
|
||||
mFadeDurationMs >= 0
|
||||
|
||||
Reference in New Issue
Block a user