|
9 | 9 | import com.bumptech.glide.Glide;
|
10 | 10 | import com.bumptech.glide.RequestManager;
|
11 | 11 | import com.bumptech.glide.load.model.GlideUrl;
|
| 12 | +import com.bumptech.glide.request.Request; |
12 | 13 | import com.facebook.react.bridge.ReadableMap;
|
13 | 14 | import com.facebook.react.bridge.WritableMap;
|
14 | 15 | import com.facebook.react.bridge.WritableNativeMap;
|
@@ -58,9 +59,7 @@ protected FastImageViewWithUrl createViewInstance(ThemedReactContext reactContex
|
58 | 59 | public void setSrc(FastImageViewWithUrl view, @Nullable ReadableMap source) {
|
59 | 60 | if (source == null || !source.hasKey("uri") || isNullOrEmpty(source.getString("uri"))) {
|
60 | 61 | // Cancel existing requests.
|
61 |
| - if (requestManager != null) { |
62 |
| - requestManager.clear(view); |
63 |
| - } |
| 62 | + clearView(view); |
64 | 63 |
|
65 | 64 | if (view.glideUrl != null) {
|
66 | 65 | FastImageOkHttpProgressGlideModule.forget(view.glideUrl.toStringUrl());
|
@@ -97,9 +96,7 @@ public void setSrc(FastImageViewWithUrl view, @Nullable ReadableMap source) {
|
97 | 96 |
|
98 | 97 | // Cancel existing request.
|
99 | 98 | view.glideUrl = glideUrl;
|
100 |
| - if (requestManager != null) { |
101 |
| - requestManager.clear(view); |
102 |
| - } |
| 99 | + clearView(view); |
103 | 100 |
|
104 | 101 | String key = glideUrl.toStringUrl();
|
105 | 102 | FastImageOkHttpProgressGlideModule.expect(key, this);
|
@@ -149,9 +146,7 @@ public void setResizeMode(FastImageViewWithUrl view, String resizeMode) {
|
149 | 146 | @Override
|
150 | 147 | public void onDropViewInstance(FastImageViewWithUrl view) {
|
151 | 148 | // This will cancel existing requests.
|
152 |
| - if (requestManager != null) { |
153 |
| - requestManager.clear(view); |
154 |
| - } |
| 149 | + clearView(view); |
155 | 150 |
|
156 | 151 | if (view.glideUrl != null) {
|
157 | 152 | final String key = view.glideUrl.toString();
|
@@ -244,4 +239,10 @@ private static boolean isActivityDestroyed(Activity activity) {
|
244 | 239 | }
|
245 | 240 |
|
246 | 241 | }
|
| 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 | + } |
247 | 248 | }
|
0 commit comments