Skip to content
Permalink
Browse files
Add "resizeMode" prop support on TextInlineView
Summary: changelog: [Android] [Added] Add "resizeMode" prop support on TextInlineView

Reviewed By: JoshuaGross

Differential Revision: D19509347

fbshipit-source-id: 0281ae6e958401aaaaa10599df892a2b60a3c615
  • Loading branch information
mdvacca authored and facebook-github-bot committed Jan 22, 2020
1 parent 6a1438c commit 68714163280695c3148544b95b05a2c1464dbbba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
@@ -22,6 +22,7 @@ rn_android_library(
react_native_target("java/com/facebook/react/modules/fresco:fresco"),
react_native_target("java/com/facebook/react/uimanager:uimanager"),
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
react_native_target("java/com/facebook/react/views/image:image"),
react_native_target("java/com/facebook/react/views/text:text"),
],
)
@@ -18,6 +18,7 @@
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.views.text.ReactTextInlineImageShadowNode;
import com.facebook.react.views.text.TextInlineImageSpan;
@@ -32,6 +33,7 @@ public class FrescoBasedReactTextInlineImageShadowNode extends ReactTextInlineIm
private final AbstractDraweeControllerBuilder mDraweeControllerBuilder;
private final @Nullable Object mCallerContext;
private float mWidth = YogaConstants.UNDEFINED;
private @Nullable String mResizeMode;
private float mHeight = YogaConstants.UNDEFINED;
private int mTintColor = 0;

@@ -97,6 +99,11 @@ public void setHeight(Dynamic height) {
}
}

@ReactProp(name = ViewProps.RESIZE_MODE)
public void setResizeMode(@Nullable String resizeMode) {
mResizeMode = resizeMode;
}

public @Nullable Uri getUri() {
return mUri;
}
@@ -136,7 +143,8 @@ public TextInlineImageSpan buildInlineImageSpan() {
getUri(),
getHeaders(),
getDraweeControllerBuilder(),
getCallerContext());
getCallerContext(),
mResizeMode);
}

public AbstractDraweeControllerBuilder getDraweeControllerBuilder() {
@@ -16,6 +16,7 @@
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder;
import com.facebook.drawee.drawable.ScalingUtils;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.interfaces.DraweeController;
@@ -25,6 +26,7 @@
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.modules.fresco.ReactNetworkImageRequest;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.views.image.ImageResizeMode;
import com.facebook.react.views.text.TextInlineImageSpan;

/**
@@ -50,6 +52,7 @@ public class FrescoBasedReactTextInlineImageSpan extends TextInlineImageSpan {
private Uri mUri;
private int mWidth;
private ReadableMap mHeaders;
private String mResizeMode;

private @Nullable TextView mTextView;

@@ -61,7 +64,8 @@ public FrescoBasedReactTextInlineImageSpan(
@Nullable Uri uri,
ReadableMap headers,
AbstractDraweeControllerBuilder draweeControllerBuilder,
@Nullable Object callerContext) {
@Nullable Object callerContext,
String resizeMode) {
mDraweeHolder = new DraweeHolder(GenericDraweeHierarchyBuilder.newInstance(resources).build());
mDraweeControllerBuilder = draweeControllerBuilder;
mCallerContext = callerContext;
@@ -70,6 +74,7 @@ public FrescoBasedReactTextInlineImageSpan(
mHeaders = headers;
mWidth = (int) (PixelUtil.toPixelFromDIP(width));
mHeight = (int) (PixelUtil.toPixelFromDIP(height));
mResizeMode = resizeMode;
}

/**
@@ -130,7 +135,7 @@ public void draw(
ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(mUri);
ImageRequest imageRequest =
ReactNetworkImageRequest.fromBuilderWithHeaders(imageRequestBuilder, mHeaders);

mDraweeHolder.getHierarchy().setActualImageScaleType(getResizeMode(mResizeMode));
DraweeController draweeController =
mDraweeControllerBuilder
.reset()
@@ -163,6 +168,10 @@ public void draw(
canvas.restore();
}

private ScalingUtils.ScaleType getResizeMode(String resizeMode) {
return ImageResizeMode.toScaleType(resizeMode);
}

@Override
public int getWidth() {
return mWidth;

0 comments on commit 6871416

Please sign in to comment.