fix: do not crash when source is invalid (#782)

To reproduce, you can use: `source={{ uri: '/' }}`
This commit is contained in:
Amaury Liet 2021-09-15 21:52:18 +02:00 committed by GitHub
parent 716c01a967
commit 5c5fefacbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

View File

@ -72,6 +72,27 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
//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.