From 5c5fefacbdbc4d02c1eb71bca88fa1d012750b87 Mon Sep 17 00:00:00 2001 From: Amaury Liet Date: Wed, 15 Sep 2021 21:52:18 +0200 Subject: [PATCH] fix: do not crash when source is invalid (#782) To reproduce, you can use: `source={{ uri: '/' }}` --- .../fastimage/FastImageViewManager.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java b/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java index f97ec717a..09b01c3b9 100644 --- a/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java +++ b/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java @@ -72,6 +72,27 @@ public void setSrc(FastImageViewWithUrl view, @Nullable ReadableMap source) { //final GlideUrl glideUrl = FastImageViewConverter.getGlideUrl(view.getContext(), source); final FastImageSource imageSource = FastImageViewConverter.getImageSource(view.getContext(), source); + if (imageSource.getUri().toString().length() == 0) { + ThemedReactContext context = (ThemedReactContext) view.getContext(); + RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class); + int viewId = view.getId(); + WritableMap event = new WritableNativeMap(); + event.putString("message", "Invalid source prop:" + source); + eventEmitter.receiveEvent(viewId, REACT_ON_ERROR_EVENT, event); + + // Cancel existing requests. + if (requestManager != null) { + requestManager.clear(view); + } + + if (view.glideUrl != null) { + FastImageOkHttpProgressGlideModule.forget(view.glideUrl.toStringUrl()); + } + // Clear the image. + view.setImageDrawable(null); + return; + } + final GlideUrl glideUrl = imageSource.getGlideUrl(); // Cancel existing request.