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
This commit is contained in:
Andrew Y. Chen 2016-12-19 11:58:21 -08:00 committed by Facebook Github Bot
parent 709a441ecf
commit 5671dc3fae

View File

@ -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();
}
}
}