Skip to content

Commit

Permalink
fix: do not crash when source is invalid (#782)
Browse files Browse the repository at this point in the history
To reproduce, you can use: `source={{ uri: '/' }}`
  • Loading branch information
AmauryLiet authored Sep 15, 2021
1 parent 716c01a commit 5c5fefa
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5c5fefa

Please sign in to comment.