Skip to content

Commit

Permalink
Add "resizeMode" prop support on TextInlineView
Browse files Browse the repository at this point in the history
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 6871416
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -136,7 +143,8 @@ public TextInlineImageSpan buildInlineImageSpan() {
getUri(),
getHeaders(),
getDraweeControllerBuilder(),
getCallerContext());
getCallerContext(),
mResizeMode);
}

public AbstractDraweeControllerBuilder getDraweeControllerBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -70,6 +74,7 @@ public FrescoBasedReactTextInlineImageSpan(
mHeaders = headers;
mWidth = (int) (PixelUtil.toPixelFromDIP(width));
mHeight = (int) (PixelUtil.toPixelFromDIP(height));
mResizeMode = resizeMode;
}

/**
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6871416

Please sign in to comment.