diff --git a/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java b/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java index 09b01c3b9..094446399 100644 --- a/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java +++ b/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java @@ -9,6 +9,7 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.load.model.GlideUrl; +import com.bumptech.glide.request.Request; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.WritableNativeMap; @@ -58,9 +59,7 @@ protected FastImageViewWithUrl createViewInstance(ThemedReactContext reactContex public void setSrc(FastImageViewWithUrl view, @Nullable ReadableMap source) { if (source == null || !source.hasKey("uri") || isNullOrEmpty(source.getString("uri"))) { // Cancel existing requests. - if (requestManager != null) { - requestManager.clear(view); - } + clearView(view); if (view.glideUrl != null) { FastImageOkHttpProgressGlideModule.forget(view.glideUrl.toStringUrl()); @@ -97,9 +96,7 @@ public void setSrc(FastImageViewWithUrl view, @Nullable ReadableMap source) { // Cancel existing request. view.glideUrl = glideUrl; - if (requestManager != null) { - requestManager.clear(view); - } + clearView(view); String key = glideUrl.toStringUrl(); FastImageOkHttpProgressGlideModule.expect(key, this); @@ -149,9 +146,7 @@ public void setResizeMode(FastImageViewWithUrl view, String resizeMode) { @Override public void onDropViewInstance(FastImageViewWithUrl view) { // This will cancel existing requests. - if (requestManager != null) { - requestManager.clear(view); - } + clearView(view); if (view.glideUrl != null) { final String key = view.glideUrl.toString(); @@ -244,4 +239,10 @@ private static boolean isActivityDestroyed(Activity activity) { } } + + private void clearView(FastImageViewWithUrl view) { + if (requestManager != null && view != null && view.getTag() != null && view.getTag() instanceof Request) { + requestManager.clear(view); + } + } }