Skip to content

Commit

Permalink
Add tint color to inline icons
Browse files Browse the repository at this point in the history
Reviewed By: achen1

Differential Revision: D7625378

fbshipit-source-id: a60cf79f32f2d4091dbddebd65af4880ebb8c2c7
  • Loading branch information
himabindugadupudi authored and facebook-github-bot committed Apr 14, 2018
1 parent af661e4 commit e8e2a6e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class FrescoBasedReactTextInlineImageShadowNode extends ReactTextInlineIm
private final @Nullable Object mCallerContext;
private float mWidth = YogaConstants.UNDEFINED;
private float mHeight = YogaConstants.UNDEFINED;
private int mTintColor = 0;

public FrescoBasedReactTextInlineImageShadowNode(
AbstractDraweeControllerBuilder draweeControllerBuilder,
Expand All @@ -54,6 +55,7 @@ private FrescoBasedReactTextInlineImageShadowNode(FrescoBasedReactTextInlineImag
mHeaders = node.mHeaders; // mHeaders is immutable
mWidth = node.mWidth;
mHeight = node.mHeight;
mTintColor = node.mTintColor;
mDraweeControllerBuilder = node.mDraweeControllerBuilder;
mCallerContext = node.mCallerContext;
mUri = node.mUri;
Expand Down Expand Up @@ -94,6 +96,11 @@ public void setHeaders(ReadableMap headers) {
mHeaders = headers;
}

@ReactProp(name = "tintColor")
public void setTintColor(int tintColor) {
mTintColor = tintColor;
}

/**
* Besides width/height, all other layout props on inline images are ignored
*/
Expand All @@ -116,7 +123,7 @@ public void setHeight(Dynamic height) {
"Inline images must not have percentage based height");
}
}

public @Nullable Uri getUri() {
return mUri;
}
Expand Down Expand Up @@ -155,6 +162,7 @@ public TextInlineImageSpan buildInlineImageSpan() {
resources,
height,
width,
mTintColor,
getUri(),
getHeaders(),
getDraweeControllerBuilder(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package com.facebook.react.views.text.frescosupport;

import android.graphics.Color;
import android.graphics.PorterDuff;
import javax.annotation.Nullable;

import android.content.res.Resources;
Expand Down Expand Up @@ -46,6 +48,7 @@ public class FrescoBasedReactTextInlineImageSpan extends TextInlineImageSpan {
private final @Nullable Object mCallerContext;

private int mHeight;
private int mTintColor;
private Uri mUri;
private int mWidth;
private ReadableMap mHeaders;
Expand All @@ -56,6 +59,7 @@ public FrescoBasedReactTextInlineImageSpan(
Resources resources,
int height,
int width,
int tintColor,
@Nullable Uri uri,
ReadableMap headers,
AbstractDraweeControllerBuilder draweeControllerBuilder,
Expand All @@ -68,6 +72,7 @@ public FrescoBasedReactTextInlineImageSpan(
mCallerContext = callerContext;

mHeight = height;
mTintColor = tintColor;
mWidth = width;
mUri = (uri != null) ? uri : Uri.EMPTY;
mHeaders = headers;
Expand Down Expand Up @@ -143,7 +148,11 @@ public void draw(

mDrawable = mDraweeHolder.getTopLevelDrawable();
mDrawable.setBounds(0, 0, mWidth, mHeight);
if(mTintColor != 0) {
mDrawable.setColorFilter(mTintColor, PorterDuff.Mode.SRC_IN);
}
mDrawable.setCallback(mTextView);

}

// NOTE: This drawing code is copied from DynamicDrawableSpan
Expand Down

0 comments on commit e8e2a6e

Please sign in to comment.