react-native-fast-image 9.3.1 → 9.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -280,6 +280,11 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
280
280
|
.asFile()
|
|
281
281
|
.load(model)
|
|
282
282
|
.apply(options)
|
|
283
|
+
// Not kept in or taken from the memory cache (asFile() skips
|
|
284
|
+
// it, but the options turn it back on): the file is only there
|
|
285
|
+
// while the disk cache keeps it, and Glide gave the path of
|
|
286
|
+
// one that clearDiskCache had deleted.
|
|
287
|
+
.skipMemoryCache(true)
|
|
283
288
|
.listener(new RequestListener<File>() {
|
|
284
289
|
@Override
|
|
285
290
|
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<File> target, boolean isFirstResource) {
|
|
@@ -307,6 +312,8 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
307
312
|
.asFile()
|
|
308
313
|
.load(model)
|
|
309
314
|
.apply(options)
|
|
315
|
+
// On disk only, as in loadFile.
|
|
316
|
+
.skipMemoryCache(true)
|
|
310
317
|
.onlyRetrieveFromCache(true)
|
|
311
318
|
.submit()
|
|
312
319
|
.get();
|
|
@@ -322,8 +329,10 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
322
329
|
return result;
|
|
323
330
|
}
|
|
324
331
|
|
|
325
|
-
// Where getCachePath looks in the caches and downloads `web` images
|
|
326
|
-
//
|
|
332
|
+
// Where getCachePath looks in the caches and downloads `web` images,
|
|
333
|
+
// writeToCache stores files, configureCache measures the disk cache and
|
|
334
|
+
// clearDiskCache empties it (blocking calls, off the UI and modules
|
|
335
|
+
// threads).
|
|
327
336
|
private static final Executor cachePathExecutor = Executors.newSingleThreadExecutor();
|
|
328
337
|
|
|
329
338
|
private static WritableMap pathResult(File file) {
|
|
@@ -590,24 +599,33 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
590
599
|
});
|
|
591
600
|
}
|
|
592
601
|
|
|
593
|
-
// On
|
|
594
|
-
// thread.
|
|
602
|
+
// On cachePathExecutor: Glide clears its disk cache off the main thread,
|
|
603
|
+
// and the native modules' thread runs every module's async methods (e.g.
|
|
604
|
+
// a fetch()'s request), which would wait for it. It's also in order with
|
|
605
|
+
// the disk work of getCachePath, writeToCache and configureCache there.
|
|
595
606
|
@ReactMethod
|
|
596
|
-
public void clearDiskCache(Promise promise) {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
607
|
+
public void clearDiskCache(final Promise promise) {
|
|
608
|
+
final ReactApplicationContext context = getReactApplicationContext();
|
|
609
|
+
cachePathExecutor.execute(new Runnable() {
|
|
610
|
+
@Override
|
|
611
|
+
public void run() {
|
|
612
|
+
try {
|
|
613
|
+
FastImageGlide.getRegistered(context).clearDiskCache();
|
|
614
|
+
} catch (RuntimeException e) {
|
|
615
|
+
promise.resolve(failure(e));
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
// And the HTTP cache of `cache: 'web'` images, which Glide
|
|
619
|
+
// doesn't cache (set up when FastImage's components are
|
|
620
|
+
// registered).
|
|
621
|
+
try {
|
|
622
|
+
FastImageOkHttpProgressGlideModule.clearWebCache();
|
|
623
|
+
} catch (IOException e) {
|
|
624
|
+
// Cleared as far as it could.
|
|
625
|
+
}
|
|
626
|
+
promise.resolve(cleared());
|
|
627
|
+
}
|
|
628
|
+
});
|
|
611
629
|
}
|
|
612
630
|
|
|
613
631
|
private static WritableMap cleared() {
|
|
@@ -832,6 +832,9 @@ class FastImageViewWithUrl extends AppCompatImageView implements ReactPointerEve
|
|
|
832
832
|
private Object mModel;
|
|
833
833
|
// Whether the loading image has loaded or failed.
|
|
834
834
|
private boolean mLoadEnded = false;
|
|
835
|
+
// Whether the loading request is the image that's showing loaded again
|
|
836
|
+
// (reloadForSize's or reblur's), which sends no events.
|
|
837
|
+
private boolean mLoadingQuietly = false;
|
|
835
838
|
// Set by reblur: the next load is the same one again, so it doesn't send
|
|
836
839
|
// onLoadStart (it sends its other events, as the load it replaces would
|
|
837
840
|
// have).
|
|
@@ -942,13 +945,16 @@ class FastImageViewWithUrl extends AppCompatImageView implements ReactPointerEve
|
|
|
942
945
|
.error(current.clone())
|
|
943
946
|
.listener(new FastImageRequestListener(null, true, false));
|
|
944
947
|
if (meanwhile == null) builder = builder.thumbnail(current);
|
|
945
|
-
into(shown, builder, meanwhile);
|
|
948
|
+
into(shown, builder, meanwhile, true);
|
|
946
949
|
}
|
|
947
950
|
|
|
948
951
|
// blurRadius changed, and nothing else that needs a reload: the image
|
|
949
952
|
// that's showing, blurred again, with no events, as reloadForSize does: it's
|
|
950
953
|
// decoded again from the cache and blurred on Glide's threads, and the view
|
|
951
|
-
// keeps the current image until then
|
|
954
|
+
// keeps the current image until then. If that fails, it shows the image
|
|
955
|
+
// from Glide's caches; cache: 'web' skips them, so the view shows
|
|
956
|
+
// defaultSource (or nothing) then. Also while it's loading again that way
|
|
957
|
+
// (e.g. the blur changes every frame): that load is replaced. A load that
|
|
952
958
|
// hasn't finished starts again with the new blur, without a second
|
|
953
959
|
// onLoadStart. Nothing loaded (defaultSource, which isn't blurred, or
|
|
954
960
|
// nothing): the next load has the new blur.
|
|
@@ -956,7 +962,7 @@ class FastImageViewWithUrl extends AppCompatImageView implements ReactPointerEve
|
|
|
956
962
|
private void reblur() {
|
|
957
963
|
if (requestManager == null || mBaseRequest == null) return;
|
|
958
964
|
RequestBuilder<Drawable> shown = mShownRequest;
|
|
959
|
-
if (shown != null && shown == mLoadingRequest) {
|
|
965
|
+
if (shown != null && (shown == mLoadingRequest || mLoadingQuietly)) {
|
|
960
966
|
RequestBuilder<Drawable> request = mBaseRequest.clone().apply(renderingOptions(mModel));
|
|
961
967
|
RequestBuilder<Drawable> current = fromCache(shown);
|
|
962
968
|
Drawable meanwhile = shownCopy(shown);
|
|
@@ -966,7 +972,7 @@ class FastImageViewWithUrl extends AppCompatImageView implements ReactPointerEve
|
|
|
966
972
|
.error(current.clone())
|
|
967
973
|
.listener(new FastImageRequestListener(null, true, false));
|
|
968
974
|
if (meanwhile == null) builder = builder.thumbnail(current);
|
|
969
|
-
into(request, builder, meanwhile);
|
|
975
|
+
into(request, builder, meanwhile, true);
|
|
970
976
|
} else if (mLoadingRequest != null && !mLoadEnded) {
|
|
971
977
|
mRestarting = true;
|
|
972
978
|
mNeedsReload = true;
|
|
@@ -1007,10 +1013,13 @@ class FastImageViewWithUrl extends AppCompatImageView implements ReactPointerEve
|
|
|
1007
1013
|
|
|
1008
1014
|
// Starts loading the request (built by builder), showing meanwhile (if
|
|
1009
1015
|
// not null) until it loads, and recording the size Glide loads it at. The size callback is added first, so it has the size by
|
|
1010
|
-
// the time the image loads, even from the memory cache.
|
|
1011
|
-
|
|
1016
|
+
// the time the image loads, even from the memory cache. Quiet: the image
|
|
1017
|
+
// that's showing, loaded again (no events).
|
|
1018
|
+
private void into(RequestBuilder<Drawable> request, RequestBuilder<Drawable> builder, @Nullable Drawable meanwhile,
|
|
1019
|
+
boolean quiet) {
|
|
1012
1020
|
final int load = mLoadCount;
|
|
1013
1021
|
mLoadingRequest = request;
|
|
1022
|
+
mLoadingQuietly = quiet;
|
|
1014
1023
|
mLoadEnded = false;
|
|
1015
1024
|
mLoadingWidth = 0;
|
|
1016
1025
|
mLoadingHeight = 0;
|
|
@@ -1218,7 +1227,7 @@ class FastImageViewWithUrl extends AppCompatImageView implements ReactPointerEve
|
|
|
1218
1227
|
if (imageSource != null)
|
|
1219
1228
|
builder.listener(new FastImageRequestListener(imageSource, thumbnail, true));
|
|
1220
1229
|
|
|
1221
|
-
into(request, builder, meanwhile);
|
|
1230
|
+
into(request, builder, meanwhile, false);
|
|
1222
1231
|
}
|
|
1223
1232
|
}
|
|
1224
1233
|
|