Pass resource drawable id to constructor directly
Summary: Instead of passing the helper to each method that uses it, just pass it to the image constructor. Reviewed By: dmmiller Differential Revision: D3364532 fbshipit-source-id: 949bdbf951875c9b8cd05d028a2c329e12d72042
This commit is contained in:
parent
c36430a0d6
commit
4acf009284
|
@ -71,19 +71,20 @@ public class ReactImageManager extends SimpleViewManager<ReactImageView> {
|
||||||
return new ReactImageView(
|
return new ReactImageView(
|
||||||
context,
|
context,
|
||||||
getDraweeControllerBuilder(),
|
getDraweeControllerBuilder(),
|
||||||
getCallerContext());
|
getCallerContext(),
|
||||||
|
mResourceDrawableIdHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In JS this is Image.props.source.uri
|
// In JS this is Image.props.source.uri
|
||||||
@ReactProp(name = "src")
|
@ReactProp(name = "src")
|
||||||
public void setSource(ReactImageView view, @Nullable String source) {
|
public void setSource(ReactImageView view, @Nullable String source) {
|
||||||
view.setSource(source, mResourceDrawableIdHelper);
|
view.setSource(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In JS this is Image.props.loadingIndicatorSource.uri
|
// In JS this is Image.props.loadingIndicatorSource.uri
|
||||||
@ReactProp(name = "loadingIndicatorSrc")
|
@ReactProp(name = "loadingIndicatorSrc")
|
||||||
public void setLoadingIndicatorSource(ReactImageView view, @Nullable String source) {
|
public void setLoadingIndicatorSource(ReactImageView view, @Nullable String source) {
|
||||||
view.setLoadingIndicatorSource(source, mResourceDrawableIdHelper);
|
view.setLoadingIndicatorSource(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactProp(name = "borderColor", customType = "Color")
|
@ReactProp(name = "borderColor", customType = "Color")
|
||||||
|
|
|
@ -11,6 +11,8 @@ package com.facebook.react.views.image;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapShader;
|
import android.graphics.BitmapShader;
|
||||||
|
@ -51,8 +53,6 @@ import com.facebook.react.uimanager.PixelUtil;
|
||||||
import com.facebook.react.uimanager.UIManagerModule;
|
import com.facebook.react.uimanager.UIManagerModule;
|
||||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper class around Fresco's GenericDraweeView, enabling persisting props across multiple view
|
* Wrapper class around Fresco's GenericDraweeView, enabling persisting props across multiple view
|
||||||
* update and consistent processing of both static and network images.
|
* update and consistent processing of both static and network images.
|
||||||
|
@ -135,6 +135,8 @@ public class ReactImageView extends GenericDraweeView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final ResourceDrawableIdHelper mResourceDrawableIdHelper;
|
||||||
|
|
||||||
private @Nullable Uri mUri;
|
private @Nullable Uri mUri;
|
||||||
private @Nullable Drawable mLoadingImageDrawable;
|
private @Nullable Drawable mLoadingImageDrawable;
|
||||||
private int mBorderColor;
|
private int mBorderColor;
|
||||||
|
@ -163,12 +165,14 @@ public class ReactImageView extends GenericDraweeView {
|
||||||
public ReactImageView(
|
public ReactImageView(
|
||||||
Context context,
|
Context context,
|
||||||
AbstractDraweeControllerBuilder draweeControllerBuilder,
|
AbstractDraweeControllerBuilder draweeControllerBuilder,
|
||||||
@Nullable Object callerContext) {
|
@Nullable Object callerContext,
|
||||||
|
ResourceDrawableIdHelper resourceDrawableIdHelper) {
|
||||||
super(context, buildHierarchy(context));
|
super(context, buildHierarchy(context));
|
||||||
mScaleType = ImageResizeMode.defaultValue();
|
mScaleType = ImageResizeMode.defaultValue();
|
||||||
mDraweeControllerBuilder = draweeControllerBuilder;
|
mDraweeControllerBuilder = draweeControllerBuilder;
|
||||||
mRoundedCornerPostprocessor = new RoundedCornerPostprocessor();
|
mRoundedCornerPostprocessor = new RoundedCornerPostprocessor();
|
||||||
mCallerContext = callerContext;
|
mCallerContext = callerContext;
|
||||||
|
mResourceDrawableIdHelper = resourceDrawableIdHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShouldNotifyLoadEvents(boolean shouldNotify) {
|
public void setShouldNotifyLoadEvents(boolean shouldNotify) {
|
||||||
|
@ -255,9 +259,7 @@ public class ReactImageView extends GenericDraweeView {
|
||||||
mIsDirty = true;
|
mIsDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSource(
|
public void setSource(@Nullable String source) {
|
||||||
@Nullable String source,
|
|
||||||
ResourceDrawableIdHelper resourceDrawableIdHelper) {
|
|
||||||
mUri = null;
|
mUri = null;
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -270,7 +272,7 @@ public class ReactImageView extends GenericDraweeView {
|
||||||
// ignore malformed uri, then attempt to extract resource ID.
|
// ignore malformed uri, then attempt to extract resource ID.
|
||||||
}
|
}
|
||||||
if (mUri == null) {
|
if (mUri == null) {
|
||||||
mUri = resourceDrawableIdHelper.getResourceDrawableUri(getContext(), source);
|
mUri = mResourceDrawableIdHelper.getResourceDrawableUri(getContext(), source);
|
||||||
mIsLocalImage = true;
|
mIsLocalImage = true;
|
||||||
} else {
|
} else {
|
||||||
mIsLocalImage = false;
|
mIsLocalImage = false;
|
||||||
|
@ -279,10 +281,8 @@ public class ReactImageView extends GenericDraweeView {
|
||||||
mIsDirty = true;
|
mIsDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoadingIndicatorSource(
|
public void setLoadingIndicatorSource(@Nullable String name) {
|
||||||
@Nullable String name,
|
Drawable drawable = mResourceDrawableIdHelper.getResourceDrawable(getContext(), name);
|
||||||
ResourceDrawableIdHelper resourceDrawableIdHelper) {
|
|
||||||
Drawable drawable = resourceDrawableIdHelper.getResourceDrawable(getContext(), name);
|
|
||||||
mLoadingImageDrawable =
|
mLoadingImageDrawable =
|
||||||
drawable != null ? (Drawable) new AutoRotateDrawable(drawable, 1000) : null;
|
drawable != null ? (Drawable) new AutoRotateDrawable(drawable, 1000) : null;
|
||||||
mIsDirty = true;
|
mIsDirty = true;
|
||||||
|
@ -313,7 +313,7 @@ public class ReactImageView extends GenericDraweeView {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean doResize = shouldResize(mUri);
|
boolean doResize = shouldResize(mUri);
|
||||||
if (doResize && (getWidth() <= 0 || getHeight() <=0)) {
|
if (doResize && (getWidth() <= 0 || getHeight() <= 0)) {
|
||||||
// If need a resize and the size is not yet set, wait until the layout pass provides one
|
// If need a resize and the size is not yet set, wait until the layout pass provides one
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue