Skip to content

Commit a7a8643

Browse files
authored
fix: null exception in FastImageViewManager.java (DylanVann#423)
1 parent 8950a38 commit a7a8643

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.bumptech.glide.Glide;
1010
import com.bumptech.glide.RequestManager;
1111
import com.bumptech.glide.load.model.GlideUrl;
12+
import com.bumptech.glide.request.Request;
1213
import com.facebook.react.bridge.ReadableMap;
1314
import com.facebook.react.bridge.WritableMap;
1415
import com.facebook.react.bridge.WritableNativeMap;
@@ -58,9 +59,7 @@ protected FastImageViewWithUrl createViewInstance(ThemedReactContext reactContex
5859
public void setSrc(FastImageViewWithUrl view, @Nullable ReadableMap source) {
5960
if (source == null || !source.hasKey("uri") || isNullOrEmpty(source.getString("uri"))) {
6061
// Cancel existing requests.
61-
if (requestManager != null) {
62-
requestManager.clear(view);
63-
}
62+
clearView(view);
6463

6564
if (view.glideUrl != null) {
6665
FastImageOkHttpProgressGlideModule.forget(view.glideUrl.toStringUrl());
@@ -97,9 +96,7 @@ public void setSrc(FastImageViewWithUrl view, @Nullable ReadableMap source) {
9796

9897
// Cancel existing request.
9998
view.glideUrl = glideUrl;
100-
if (requestManager != null) {
101-
requestManager.clear(view);
102-
}
99+
clearView(view);
103100

104101
String key = glideUrl.toStringUrl();
105102
FastImageOkHttpProgressGlideModule.expect(key, this);
@@ -149,9 +146,7 @@ public void setResizeMode(FastImageViewWithUrl view, String resizeMode) {
149146
@Override
150147
public void onDropViewInstance(FastImageViewWithUrl view) {
151148
// This will cancel existing requests.
152-
if (requestManager != null) {
153-
requestManager.clear(view);
154-
}
149+
clearView(view);
155150

156151
if (view.glideUrl != null) {
157152
final String key = view.glideUrl.toString();
@@ -244,4 +239,10 @@ private static boolean isActivityDestroyed(Activity activity) {
244239
}
245240

246241
}
242+
243+
private void clearView(FastImageViewWithUrl view) {
244+
if (requestManager != null && view != null && view.getTag() != null && view.getTag() instanceof Request) {
245+
requestManager.clear(view);
246+
}
247+
}
247248
}

0 commit comments

Comments
 (0)