react-native-fast-image 9.3.7 → 10.1.0
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.
- package/README.md +97 -61
- package/RNFastImage.podspec +14 -9
- package/android/build.gradle +21 -47
- package/android/consumer-rules.pro +7 -7
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageAnimatable.java +1 -1
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageAnimated.java +2 -2
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageApng.java +2 -2
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageBlur.java +4 -6
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageCacheControl.java +1 -1
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageCacheLimits.java +4 -1
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageCacheWrite.java +1 -1
- package/android/src/main/java/com/fastimage/FastImageCrop.java +92 -0
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageEvent.java +2 -3
- package/android/src/main/java/com/fastimage/FastImageEvents.java +74 -0
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageGif.java +1 -1
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageGlide.java +13 -3
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageGlideModule.java +1 -1
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageKeyedGlideUrl.java +1 -1
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageOkHttpProgressGlideModule.java +49 -14
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageRequestListener.java +6 -1
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageSharedDownloads.java +1 -1
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageSource.java +12 -1
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageSourceSize.java +12 -2
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageSvg.java +3 -3
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageSvgRenderer.java +1 -1
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageUrl.java +1 -1
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageViewConverter.java +24 -9
- package/android/src/main/java/com/fastimage/FastImageViewManager.java +591 -0
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageViewModule.java +50 -28
- package/android/src/main/java/com/fastimage/FastImageViewPackage.java +51 -0
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageViewWithUrl.java +352 -126
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageWebGlideUrl.java +1 -1
- package/app.plugin.js +2 -7
- package/dist/index.cjs.js +276 -157
- package/dist/index.cjs.js.flow +34 -17
- package/dist/index.cjs.web.js +211 -61
- package/dist/index.cjs.web.js.flow +34 -17
- package/dist/index.d.ts +108 -58
- package/dist/index.js +278 -159
- package/dist/index.js.flow +34 -17
- package/dist/index.web.js +212 -62
- package/dist/index.web.js.flow +34 -17
- package/dist/objectFit.d.ts +2 -2
- package/dist/objectPosition.d.ts +42 -0
- package/dist/specs/FastImageViewNativeComponent.d.ts +48 -0
- package/dist/specs/NativeFastImageModule.d.ts +11 -0
- package/dist/warnings.d.ts +3 -0
- package/ios/FastImage/FFFDownsampledImage.h +4 -8
- package/ios/FastImage/FFFDownsampledImage.m +0 -34
- package/ios/FastImage/FFFastImageModule.h +8 -0
- package/ios/FastImage/{FFFastImageViewManager.m → FFFastImageModule.mm} +89 -59
- package/ios/FastImage/FFFastImageSource.h +4 -0
- package/ios/FastImage/FFFastImageSource.m +5 -1
- package/ios/FastImage/FFFastImageView.h +36 -7
- package/ios/FastImage/FFFastImageView.m +229 -172
- package/ios/FastImage/FFFastImageViewComponentView.h +11 -0
- package/ios/FastImage/FFFastImageViewComponentView.mm +325 -0
- package/ios/FastImage/RCTConvert+FFFastImage.h +1 -1
- package/ios/FastImage/RCTConvert+FFFastImage.m +9 -10
- package/package.json +28 -9
- package/src/constants.ts +28 -0
- package/src/index.js.flow +180 -0
- package/src/index.tsx +1128 -0
- package/src/index.web.tsx +548 -0
- package/src/objectFit.ts +48 -0
- package/src/objectPosition.ts +243 -0
- package/src/specs/FastImageViewNativeComponent.ts +83 -0
- package/src/specs/NativeFastImageModule.ts +35 -0
- package/src/warnings.ts +37 -0
- package/android/src/main/AndroidManifestNew.xml +0 -3
- package/android/src/main/java/com/dylanvann/fastimage/FastImageCookieHandler.java +0 -63
- package/android/src/main/java/com/dylanvann/fastimage/FastImageEvents.java +0 -49
- package/android/src/main/java/com/dylanvann/fastimage/FastImageProgressListener.java +0 -18
- package/android/src/main/java/com/dylanvann/fastimage/FastImageShadowNode.java +0 -21
- package/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java +0 -379
- package/android/src/main/java/com/dylanvann/fastimage/FastImageViewPackage.java +0 -27
- package/ios/FastImage/FFFastImageViewManager.h +0 -5
package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageViewModule.java
RENAMED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
package com.
|
|
1
|
+
package com.fastimage;
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.graphics.BitmapFactory;
|
|
5
5
|
import android.graphics.drawable.Drawable;
|
|
6
6
|
import android.net.Uri;
|
|
7
7
|
|
|
8
|
-
import androidx.annotation.NonNull;
|
|
9
8
|
import androidx.annotation.Nullable;
|
|
10
9
|
|
|
11
10
|
import com.bumptech.glide.Glide;
|
|
@@ -22,10 +21,9 @@ import com.bumptech.glide.request.target.Target;
|
|
|
22
21
|
import com.facebook.react.bridge.Arguments;
|
|
23
22
|
import com.facebook.react.bridge.Promise;
|
|
24
23
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
25
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
26
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
27
24
|
import com.facebook.react.bridge.ReadableArray;
|
|
28
25
|
import com.facebook.react.bridge.ReadableMap;
|
|
26
|
+
import com.facebook.react.bridge.ReadableType;
|
|
29
27
|
import com.facebook.react.bridge.UiThreadUtil;
|
|
30
28
|
import com.facebook.react.bridge.WritableArray;
|
|
31
29
|
import com.facebook.react.bridge.WritableMap;
|
|
@@ -38,20 +36,14 @@ import java.util.ArrayDeque;
|
|
|
38
36
|
import java.util.concurrent.Executor;
|
|
39
37
|
import java.util.concurrent.Executors;
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
// FastImage's functions (preload, getCachePath, writeToCache and the caches'
|
|
40
|
+
// settings): the FastImageModule TurboModule (src/specs).
|
|
41
|
+
class FastImageViewModule extends NativeFastImageModuleSpec {
|
|
44
42
|
|
|
45
43
|
FastImageViewModule(ReactApplicationContext reactContext) {
|
|
46
44
|
super(reactContext);
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
@NonNull
|
|
50
|
-
@Override
|
|
51
|
-
public String getName() {
|
|
52
|
-
return REACT_CLASS;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
47
|
// At most this many preloaded sources load at a time, across all preload
|
|
56
48
|
// calls (the same as SDWebImagePrefetcher's default on iOS), so a long
|
|
57
49
|
// list doesn't queue hundreds of requests ahead of the images the app is
|
|
@@ -112,7 +104,7 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
112
104
|
// failed: { ok, width, height } or { ok: false, error }. Never rejects.
|
|
113
105
|
// A remote source with memoryCache false is only downloaded to the disk
|
|
114
106
|
// cache, without decoding it (its size comes from the header).
|
|
115
|
-
@
|
|
107
|
+
@Override
|
|
116
108
|
public void preload(final ReadableArray sources, final Promise promise) {
|
|
117
109
|
final ReactApplicationContext context = getReactApplicationContext();
|
|
118
110
|
UiThreadUtil.runOnUiThread(new Runnable() {
|
|
@@ -144,6 +136,13 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
144
136
|
finishOne.run();
|
|
145
137
|
continue;
|
|
146
138
|
}
|
|
139
|
+
// Views decode an image for their own size, so one only
|
|
140
|
+
// preloaded into memory would be downloaded again.
|
|
141
|
+
if (!FastImageViewConverter.isDiskCache(source)) {
|
|
142
|
+
results[i] = failure(NOT_ON_DISK);
|
|
143
|
+
finishOne.run();
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
147
146
|
final FastImageSource imageSource = FastImageViewConverter.getImageSource(context, source);
|
|
148
147
|
// A uri that can't be resolved (e.g. a relative path) resolves
|
|
149
148
|
// to an empty one.
|
|
@@ -322,6 +321,10 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
322
321
|
}
|
|
323
322
|
}
|
|
324
323
|
|
|
324
|
+
// preload's, getCachePath's and writeToCache's error for a source with
|
|
325
|
+
// diskCache false.
|
|
326
|
+
private static final String NOT_ON_DISK = "The source has diskCache: false, so it isn't kept on disk";
|
|
327
|
+
|
|
325
328
|
private static WritableMap failure(String error) {
|
|
326
329
|
WritableMap result = Arguments.createMap();
|
|
327
330
|
result.putBoolean("ok", false);
|
|
@@ -347,9 +350,13 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
347
350
|
// preloads' queue): { ok, path } or { ok: false, error }. Never rejects.
|
|
348
351
|
// With `cacheOnly`, or a cacheKey without a uri, it doesn't download. A
|
|
349
352
|
// local file is its own path.
|
|
350
|
-
@
|
|
353
|
+
@Override
|
|
351
354
|
public void getCachePath(final ReadableMap source, final Promise promise) {
|
|
352
355
|
final ReactApplicationContext context = getReactApplicationContext();
|
|
356
|
+
if (!FastImageViewConverter.isDiskCache(source)) {
|
|
357
|
+
promise.resolve(failure(NOT_ON_DISK));
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
353
360
|
if (!FastImageViewConverter.hasUri(source)) {
|
|
354
361
|
// `web` images ignore cacheKey.
|
|
355
362
|
final String cacheKey = FastImageViewConverter.getCacheControl(source) == FastImageCacheControl.WEB
|
|
@@ -479,9 +486,13 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
479
486
|
// that's already cached (Glide can't: a new image should get a new
|
|
480
487
|
// cacheKey), and doesn't store `web` sources (kept only in an HTTP cache,
|
|
481
488
|
// which can't be added to).
|
|
482
|
-
@
|
|
489
|
+
@Override
|
|
483
490
|
public void writeToCache(final ReadableMap source, final String file, final Promise promise) {
|
|
484
491
|
final ReactApplicationContext context = getReactApplicationContext();
|
|
492
|
+
if (!FastImageViewConverter.isDiskCache(source)) {
|
|
493
|
+
promise.resolve(failure(NOT_ON_DISK));
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
485
496
|
if (FastImageViewConverter.getCacheControl(source) == FastImageCacheControl.WEB) {
|
|
486
497
|
promise.resolve(failure("Can't store cache: 'web' images (they're kept in an HTTP cache)"));
|
|
487
498
|
return;
|
|
@@ -546,21 +557,21 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
546
557
|
});
|
|
547
558
|
}
|
|
548
559
|
|
|
549
|
-
// Saves maxDiskSize (bytes, 0 for no limit;
|
|
550
|
-
// manifest or Glide's default), which
|
|
551
|
-
// Glide starts: now if it hasn't started
|
|
552
|
-
// next launch. Resolves with the limit in
|
|
553
|
-
// bytes the disk cache uses now: { maxDiskSize, diskSize }, or {} if the
|
|
560
|
+
// Saves maxDiskSize (bytes, 0 for no limit; its name in `reset`, null in
|
|
561
|
+
// JS, goes back to the app's manifest or Glide's default), which
|
|
562
|
+
// FastImageGlideModule applies when Glide starts: now if it hasn't started
|
|
563
|
+
// yet (this starts it), or on the next launch. Resolves with the limit in
|
|
564
|
+
// effect and the bytes the disk cache uses now: { maxDiskSize, diskSize }, or {} if the
|
|
554
565
|
// app starts Glide with its own AppGlideModule (its size and folder are
|
|
555
566
|
// the app's). maxDiskAge and maxMemorySize are iOS only (Glide has no
|
|
556
567
|
// age limit, and sizes its memory cache from the screen).
|
|
557
|
-
@
|
|
568
|
+
@Override
|
|
558
569
|
public void configureCache(final ReadableMap limits, final Promise promise) {
|
|
559
570
|
final ReactApplicationContext context = getReactApplicationContext();
|
|
560
|
-
if (limits
|
|
561
|
-
FastImageCacheLimits.saveMaxDiskSize(context,
|
|
562
|
-
|
|
563
|
-
|
|
571
|
+
if (isReset(limits, "maxDiskSize")) {
|
|
572
|
+
FastImageCacheLimits.saveMaxDiskSize(context, null);
|
|
573
|
+
} else if (limits.hasKey("maxDiskSize") && limits.getType("maxDiskSize") == ReadableType.Number) {
|
|
574
|
+
FastImageCacheLimits.saveMaxDiskSize(context, (long) Math.max(limits.getDouble("maxDiskSize"), 0));
|
|
564
575
|
}
|
|
565
576
|
cachePathExecutor.execute(new Runnable() {
|
|
566
577
|
@Override
|
|
@@ -577,10 +588,21 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
577
588
|
});
|
|
578
589
|
}
|
|
579
590
|
|
|
591
|
+
// Whether JS reset the limit (set it to null): their names come in
|
|
592
|
+
// `reset`, as iOS's TurboModule leaves null values out.
|
|
593
|
+
private static boolean isReset(ReadableMap limits, String name) {
|
|
594
|
+
if (!limits.hasKey("reset") || limits.getType("reset") != ReadableType.Array) return false;
|
|
595
|
+
ReadableArray reset = limits.getArray("reset");
|
|
596
|
+
for (int i = 0; i < reset.size(); i++) {
|
|
597
|
+
if (reset.getType(i) == ReadableType.String && name.equals(reset.getString(i))) return true;
|
|
598
|
+
}
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
|
|
580
602
|
// The cache functions use the app's context, not the current Activity's:
|
|
581
603
|
// there may be no Activity while JS runs (e.g. after Android destroyed it
|
|
582
604
|
// in the background). Glide clears its memory cache on the main thread.
|
|
583
|
-
@
|
|
605
|
+
@Override
|
|
584
606
|
public void clearMemoryCache(final Promise promise) {
|
|
585
607
|
final ReactApplicationContext context = getReactApplicationContext();
|
|
586
608
|
UiThreadUtil.runOnUiThread(new Runnable() {
|
|
@@ -603,7 +625,7 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
603
625
|
// and the native modules' thread runs every module's async methods (e.g.
|
|
604
626
|
// a fetch()'s request), which would wait for it. It's also in order with
|
|
605
627
|
// the disk work of getCachePath, writeToCache and configureCache there.
|
|
606
|
-
@
|
|
628
|
+
@Override
|
|
607
629
|
public void clearDiskCache(final Promise promise) {
|
|
608
630
|
final ReactApplicationContext context = getReactApplicationContext();
|
|
609
631
|
cachePathExecutor.execute(new Runnable() {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
package com.fastimage;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
import com.facebook.react.BaseReactPackage;
|
|
7
|
+
import com.facebook.react.bridge.NativeModule;
|
|
8
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
10
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
11
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
12
|
+
|
|
13
|
+
import java.util.Collections;
|
|
14
|
+
import java.util.List;
|
|
15
|
+
import java.util.Map;
|
|
16
|
+
|
|
17
|
+
// The FastImageView component and the FastImageModule TurboModule.
|
|
18
|
+
public class FastImageViewPackage extends BaseReactPackage {
|
|
19
|
+
@Nullable
|
|
20
|
+
@Override
|
|
21
|
+
public NativeModule getModule(@NonNull String name, @NonNull ReactApplicationContext reactContext) {
|
|
22
|
+
if (!NativeFastImageModuleSpec.NAME.equals(name)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
FastImageCacheLimits.loadInBackground(reactContext);
|
|
26
|
+
return new FastImageViewModule(reactContext);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@NonNull
|
|
30
|
+
@Override
|
|
31
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
32
|
+
Map<String, ReactModuleInfo> modules = Collections.singletonMap(
|
|
33
|
+
NativeFastImageModuleSpec.NAME,
|
|
34
|
+
new ReactModuleInfo(
|
|
35
|
+
NativeFastImageModuleSpec.NAME,
|
|
36
|
+
FastImageViewModule.class.getName(),
|
|
37
|
+
false, // canOverrideExistingModule
|
|
38
|
+
false, // needsEagerInit
|
|
39
|
+
false, // isCxxModule
|
|
40
|
+
true // isTurboModule
|
|
41
|
+
));
|
|
42
|
+
return () -> modules;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@NonNull
|
|
46
|
+
@Override
|
|
47
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
48
|
+
FastImageCacheLimits.loadInBackground(reactContext);
|
|
49
|
+
return Collections.<ViewManager>singletonList(new FastImageViewManager());
|
|
50
|
+
}
|
|
51
|
+
}
|