From 5671dc3fae5ab9537d30bbf30ab4b382e1417d26 Mon Sep 17 00:00:00 2001 From: "Andrew Y. Chen" Date: Mon, 19 Dec 2016 11:58:21 -0800 Subject: [PATCH] Add warning for missing local image resources Summary: Show a toast (since there isn't an easy way to show the yellow box) Reviewed By: AaaChiuuu Differential Revision: D4336435 fbshipit-source-id: 01b0dbdaabf51be3d23aab5c72ab2a701fcb8f80 --- .../react/views/image/ReactImageView.java | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) 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 09de651a9..a099d08a8 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 @@ -28,8 +28,11 @@ import android.graphics.RectF; import android.graphics.Shader; import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.widget.Toast; import com.facebook.common.util.UriUtil; +import com.facebook.react.common.build.ReactBuildConfig; import com.facebook.yoga.YogaConstants; import com.facebook.drawee.controller.AbstractDraweeControllerBuilder; import com.facebook.drawee.controller.BaseControllerListener; @@ -270,15 +273,26 @@ public class ReactImageView extends GenericDraweeView { if (sources != null && sources.size() != 0) { // Optimize for the case where we have just one uri, case in which we don't need the sizes if (sources.size() == 1) { - mSources.add(new ImageSource(getContext(), sources.getMap(0).getString("uri"))); + ReadableMap source = sources.getMap(0); + String uri = source.getString("uri"); + ImageSource imageSource = new ImageSource(getContext(), uri); + mSources.add(imageSource); + if (Uri.EMPTY.equals(imageSource.getUri())) { + warnImageSource(uri); + } } else { for (int idx = 0; idx < sources.size(); idx++) { ReadableMap source = sources.getMap(idx); - mSources.add(new ImageSource( - getContext(), - source.getString("uri"), - source.getDouble("width"), - source.getDouble("height"))); + String uri = source.getString("uri"); + ImageSource imageSource = new ImageSource( + getContext(), + uri, + source.getDouble("width"), + source.getDouble("height")); + mSources.add(imageSource); + if (Uri.EMPTY.equals(imageSource.getUri())) { + warnImageSource(uri); + } } } } @@ -470,4 +484,13 @@ public class ReactImageView extends GenericDraweeView { return false; } } + + private void warnImageSource(String uri) { + if (ReactBuildConfig.DEBUG) { + Toast.makeText( + getContext(), + "Warning: Image source \"" + uri + "\" doesn't exist", + Toast.LENGTH_SHORT).show(); + } + } }