diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java index 5eb7a7febcf78b..08a2cd7fcf1e5e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java @@ -67,8 +67,6 @@ public class ReactImageView extends GenericDraweeView { public static final int REMOTE_IMAGE_FADE_DURATION_MS = 300; - public static final String REMOTE_TRANSPARENT_BITMAP_URI = - "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="; private static float[] sComputedCornerRadii = new float[4]; @@ -309,30 +307,30 @@ public void setSource(@Nullable ReadableArray sources) { List tmpSources = new LinkedList<>(); if (sources == null || sources.size() == 0) { - ImageSource imageSource = new ImageSource(getContext(), REMOTE_TRANSPARENT_BITMAP_URI); + tmpSources.add(ImageSource.getTransparentBitmapImageSource(getContext())); + } else if (sources.size() == 1) { + // Optimize for the case where we have just one uri, case in which we don't need the sizes + ReadableMap source = sources.getMap(0); + ImageSource imageSource = new ImageSource(getContext(), source.getString("uri")); + if (Uri.EMPTY.equals(imageSource.getUri())) { + warnImageSource(source.getString("uri")); + imageSource = ImageSource.getTransparentBitmapImageSource(getContext()); + } tmpSources.add(imageSource); } else { - // Optimize for the case where we have just one uri, case in which we don't need the sizes - if (sources.size() == 1) { - ReadableMap source = sources.getMap(0); - String uri = source.getString("uri"); - ImageSource imageSource = new ImageSource(getContext(), uri); - tmpSources.add(imageSource); + for (int idx = 0; idx < sources.size(); idx++) { + ReadableMap source = sources.getMap(idx); + ImageSource imageSource = + new ImageSource( + getContext(), + source.getString("uri"), + source.getDouble("width"), + source.getDouble("height")); if (Uri.EMPTY.equals(imageSource.getUri())) { - warnImageSource(uri); - } - } else { - for (int idx = 0; idx < sources.size(); idx++) { - ReadableMap source = sources.getMap(idx); - String uri = source.getString("uri"); - ImageSource imageSource = - new ImageSource( - getContext(), uri, source.getDouble("width"), source.getDouble("height")); - tmpSources.add(imageSource); - if (Uri.EMPTY.equals(imageSource.getUri())) { - warnImageSource(uri); - } + warnImageSource(source.getString("uri")); + imageSource = ImageSource.getTransparentBitmapImageSource(getContext()); } + tmpSources.add(imageSource); } } @@ -568,8 +566,7 @@ private boolean isTiled() { private void setSourceImage() { mImageSource = null; if (mSources.isEmpty()) { - ImageSource imageSource = new ImageSource(getContext(), REMOTE_TRANSPARENT_BITMAP_URI); - mSources.add(imageSource); + mSources.add(ImageSource.getTransparentBitmapImageSource(getContext())); } else if (hasMultipleSources()) { MultiSourceResult multiSource = MultiSourceHelper.getBestSourceForSize(getWidth(), getHeight(), mSources); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/imagehelper/ImageSource.java b/ReactAndroid/src/main/java/com/facebook/react/views/imagehelper/ImageSource.java index 94a3e1c8ace973..6a5361be9690f5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/imagehelper/ImageSource.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/imagehelper/ImageSource.java @@ -9,14 +9,15 @@ import android.content.Context; import android.net.Uri; -import androidx.annotation.Nullable; -import com.facebook.infer.annotation.Assertions; import java.util.Objects; /** Class describing an image source (network URI or resource) and size. */ public class ImageSource { - private @Nullable Uri mUri; + private static final String TRANSPARENT_BITMAP_URI = + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="; + + private Uri mUri; private String mSource; private double mSize; private boolean isResource; @@ -30,6 +31,10 @@ public ImageSource(Context context, String source, double width, double height) mUri = computeUri(context); } + public static ImageSource getTransparentBitmapImageSource(Context context) { + return new ImageSource(context, TRANSPARENT_BITMAP_URI); + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -57,7 +62,7 @@ public String getSource() { /** Get the URI for this image - can be either a parsed network URI or a resource URI. */ public Uri getUri() { - return Assertions.assertNotNull(mUri); + return mUri; } /** Get the area of this image. */