react-native-fast-image 9.3.6 → 10.0.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 +87 -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 +3 -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 +36 -9
- 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 +1 -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 +7 -8
- package/android/src/main/java/com/fastimage/FastImageViewManager.java +591 -0
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageViewModule.java +31 -28
- package/android/src/main/java/com/fastimage/FastImageViewPackage.java +51 -0
- package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageViewWithUrl.java +362 -129
- 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 +33 -17
- package/dist/index.cjs.web.js +211 -61
- package/dist/index.cjs.web.js.flow +33 -17
- package/dist/index.d.ts +83 -58
- package/dist/index.js +278 -159
- package/dist/index.js.flow +33 -17
- package/dist/index.web.js +212 -62
- package/dist/index.web.js.flow +33 -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} +70 -59
- package/ios/FastImage/FFFastImageView.h +36 -7
- package/ios/FastImage/FFFastImageView.m +201 -164
- 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 +7 -10
- package/package.json +28 -9
- package/src/constants.ts +28 -0
- package/src/index.js.flow +179 -0
- package/src/index.tsx +1103 -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() {
|
|
@@ -347,7 +339,7 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
347
339
|
// preloads' queue): { ok, path } or { ok: false, error }. Never rejects.
|
|
348
340
|
// With `cacheOnly`, or a cacheKey without a uri, it doesn't download. A
|
|
349
341
|
// local file is its own path.
|
|
350
|
-
@
|
|
342
|
+
@Override
|
|
351
343
|
public void getCachePath(final ReadableMap source, final Promise promise) {
|
|
352
344
|
final ReactApplicationContext context = getReactApplicationContext();
|
|
353
345
|
if (!FastImageViewConverter.hasUri(source)) {
|
|
@@ -479,7 +471,7 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
479
471
|
// that's already cached (Glide can't: a new image should get a new
|
|
480
472
|
// cacheKey), and doesn't store `web` sources (kept only in an HTTP cache,
|
|
481
473
|
// which can't be added to).
|
|
482
|
-
@
|
|
474
|
+
@Override
|
|
483
475
|
public void writeToCache(final ReadableMap source, final String file, final Promise promise) {
|
|
484
476
|
final ReactApplicationContext context = getReactApplicationContext();
|
|
485
477
|
if (FastImageViewConverter.getCacheControl(source) == FastImageCacheControl.WEB) {
|
|
@@ -546,21 +538,21 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
546
538
|
});
|
|
547
539
|
}
|
|
548
540
|
|
|
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
|
|
541
|
+
// Saves maxDiskSize (bytes, 0 for no limit; its name in `reset`, null in
|
|
542
|
+
// JS, goes back to the app's manifest or Glide's default), which
|
|
543
|
+
// FastImageGlideModule applies when Glide starts: now if it hasn't started
|
|
544
|
+
// yet (this starts it), or on the next launch. Resolves with the limit in
|
|
545
|
+
// effect and the bytes the disk cache uses now: { maxDiskSize, diskSize }, or {} if the
|
|
554
546
|
// app starts Glide with its own AppGlideModule (its size and folder are
|
|
555
547
|
// the app's). maxDiskAge and maxMemorySize are iOS only (Glide has no
|
|
556
548
|
// age limit, and sizes its memory cache from the screen).
|
|
557
|
-
@
|
|
549
|
+
@Override
|
|
558
550
|
public void configureCache(final ReadableMap limits, final Promise promise) {
|
|
559
551
|
final ReactApplicationContext context = getReactApplicationContext();
|
|
560
|
-
if (limits
|
|
561
|
-
FastImageCacheLimits.saveMaxDiskSize(context,
|
|
562
|
-
|
|
563
|
-
|
|
552
|
+
if (isReset(limits, "maxDiskSize")) {
|
|
553
|
+
FastImageCacheLimits.saveMaxDiskSize(context, null);
|
|
554
|
+
} else if (limits.hasKey("maxDiskSize") && limits.getType("maxDiskSize") == ReadableType.Number) {
|
|
555
|
+
FastImageCacheLimits.saveMaxDiskSize(context, (long) Math.max(limits.getDouble("maxDiskSize"), 0));
|
|
564
556
|
}
|
|
565
557
|
cachePathExecutor.execute(new Runnable() {
|
|
566
558
|
@Override
|
|
@@ -577,10 +569,21 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
577
569
|
});
|
|
578
570
|
}
|
|
579
571
|
|
|
572
|
+
// Whether JS reset the limit (set it to null): their names come in
|
|
573
|
+
// `reset`, as iOS's TurboModule leaves null values out.
|
|
574
|
+
private static boolean isReset(ReadableMap limits, String name) {
|
|
575
|
+
if (!limits.hasKey("reset") || limits.getType("reset") != ReadableType.Array) return false;
|
|
576
|
+
ReadableArray reset = limits.getArray("reset");
|
|
577
|
+
for (int i = 0; i < reset.size(); i++) {
|
|
578
|
+
if (reset.getType(i) == ReadableType.String && name.equals(reset.getString(i))) return true;
|
|
579
|
+
}
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
|
|
580
583
|
// The cache functions use the app's context, not the current Activity's:
|
|
581
584
|
// there may be no Activity while JS runs (e.g. after Android destroyed it
|
|
582
585
|
// in the background). Glide clears its memory cache on the main thread.
|
|
583
|
-
@
|
|
586
|
+
@Override
|
|
584
587
|
public void clearMemoryCache(final Promise promise) {
|
|
585
588
|
final ReactApplicationContext context = getReactApplicationContext();
|
|
586
589
|
UiThreadUtil.runOnUiThread(new Runnable() {
|
|
@@ -603,7 +606,7 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
|
|
|
603
606
|
// and the native modules' thread runs every module's async methods (e.g.
|
|
604
607
|
// a fetch()'s request), which would wait for it. It's also in order with
|
|
605
608
|
// the disk work of getCachePath, writeToCache and configureCache there.
|
|
606
|
-
@
|
|
609
|
+
@Override
|
|
607
610
|
public void clearDiskCache(final Promise promise) {
|
|
608
611
|
final ReactApplicationContext context = getReactApplicationContext();
|
|
609
612
|
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
|
+
}
|