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
|
@@ -54,41 +54,7 @@ static CGSize FFFPixelSize(NSData* data) {
|
|
|
54
54
|
|
|
55
55
|
@implementation FFFDownsampledImage
|
|
56
56
|
|
|
57
|
-
+ (BOOL) isSupported {
|
|
58
|
-
static BOOL supported = NO;
|
|
59
|
-
static dispatch_once_t once;
|
|
60
|
-
dispatch_once(&once, ^{
|
|
61
|
-
// No animated image coder takes JPEG, so before SDWebImage 5.19
|
|
62
|
-
// SDAnimatedImage returned nil for one, and SDWebImage decoded it with
|
|
63
|
-
// its thumbnail options as they are (stretched to the box).
|
|
64
|
-
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
|
65
|
-
CGContextRef context = CGBitmapContextCreate(NULL, 1, 1, 8, 4, colorSpace, kCGImageAlphaNoneSkipLast);
|
|
66
|
-
CGColorSpaceRelease(colorSpace);
|
|
67
|
-
CGImageRef pixel = context ? CGBitmapContextCreateImage(context) : NULL;
|
|
68
|
-
if (context) {
|
|
69
|
-
CGContextRelease(context);
|
|
70
|
-
}
|
|
71
|
-
if (!pixel) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
NSMutableData* jpeg = [NSMutableData data];
|
|
75
|
-
CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef) jpeg, CFSTR("public.jpeg"), 1, NULL);
|
|
76
|
-
if (destination) {
|
|
77
|
-
CGImageDestinationAddImage(destination, pixel, NULL);
|
|
78
|
-
CGImageDestinationFinalize(destination);
|
|
79
|
-
CFRelease(destination);
|
|
80
|
-
}
|
|
81
|
-
CGImageRelease(pixel);
|
|
82
|
-
supported = jpeg.length > 0 && [[SDAnimatedImage alloc] initWithData: jpeg scale: 1 options: nil] != nil;
|
|
83
|
-
});
|
|
84
|
-
return supported;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
57
|
+ (void) addFullSizeToContext: (SDWebImageMutableContext*)context {
|
|
88
|
-
if (![self isSupported]) {
|
|
89
|
-
context[SDWebImageContextAnimatedImageClass] = [SDAnimatedImage class];
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
58
|
context[SDWebImageContextAnimatedImageClass] = [FFFDownsampledImage class];
|
|
93
59
|
context[SDWebImageContextImageDecodeOptions] = @{FFFDecodeSourceSize: [FFFSourceSize new]};
|
|
94
60
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <RNFastImageSpec/RNFastImageSpec.h>
|
|
3
|
+
|
|
4
|
+
// FastImage's functions (preload, getCachePath, writeToCache and the caches'
|
|
5
|
+
// settings): the FastImageModule TurboModule (src/specs).
|
|
6
|
+
@interface FFFastImageModule : NSObject <NativeFastImageModuleSpec>
|
|
7
|
+
|
|
8
|
+
@end
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
#import "
|
|
1
|
+
#import "FFFastImageModule.h"
|
|
2
|
+
#import "RCTConvert+FFFastImage.h"
|
|
2
3
|
#import "FFFastImageView.h"
|
|
3
4
|
#import "FFFDownsampledImage.h"
|
|
4
5
|
|
|
5
6
|
#import <SDWebImage/SDImageCache.h>
|
|
7
|
+
#import <SDWebImage/SDImageCoderHelper.h>
|
|
6
8
|
#import <SDWebImage/SDWebImageManager.h>
|
|
7
9
|
#import <SDWebImage/SDWebImageError.h>
|
|
8
10
|
#import <SDWebImage/SDWebImagePrefetcher.h>
|
|
@@ -41,8 +43,7 @@ static NSNumber *FFFCacheLimit(NSString *name)
|
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
// Sets a limit in SDWebImage's cache config: 0 for no limit, nil for
|
|
44
|
-
// SDWebImage's default. maxDiskAge counts from when an image was last used
|
|
45
|
-
// (SDWebImage's default from 5.21; before, from when it was stored).
|
|
46
|
+
// SDWebImage's default. maxDiskAge counts from when an image was last used.
|
|
46
47
|
static void FFFSetCacheLimit(SDImageCacheConfig *config, NSString *name, NSNumber *value)
|
|
47
48
|
{
|
|
48
49
|
double limit = MAX(value.doubleValue, 0);
|
|
@@ -54,6 +55,8 @@ static void FFFSetCacheLimit(SDImageCacheConfig *config, NSString *name, NSNumbe
|
|
|
54
55
|
// SDWebImage never expires images with a negative age (with 0 it
|
|
55
56
|
// would remove them all).
|
|
56
57
|
config.maxDiskAge = limit > 0 ? limit : -1;
|
|
58
|
+
// SDWebImage's default; set in case the app changed it, as FastImage
|
|
59
|
+
// documents maxDiskAge as counted from an image's last use.
|
|
57
60
|
config.diskCacheExpireType = SDImageCacheConfigExpireTypeAccessDate;
|
|
58
61
|
} else {
|
|
59
62
|
config.maxDiskAge = 60 * 60 * 24 * 7;
|
|
@@ -76,50 +79,51 @@ static unsigned long long FFFFolderSize(NSString *path)
|
|
|
76
79
|
return size;
|
|
77
80
|
}
|
|
78
81
|
|
|
79
|
-
|
|
82
|
+
// Runs once per launch, before FastImage first uses SDWebImage's cache: from
|
|
83
|
+
// FFFastImageModule's +initialize (on the JS thread: React Native creates the
|
|
84
|
+
// app's module providers, this class among them, at the first native module JS
|
|
85
|
+
// asks for) or FFFastImageView's (main thread), whichever comes first;
|
|
86
|
+
// dispatch_once makes the other wait until the limits are set. Image loads
|
|
87
|
+
// don't read the limits: SDWebImage reads the disk ones when it trims the disk
|
|
88
|
+
// cache (on its I/O queue, when the app goes to the background or closes), and
|
|
89
|
+
// the memory one is its NSCache's cost limit (NSCache is thread-safe).
|
|
90
|
+
void FFFApplyCacheLimits(void)
|
|
91
|
+
{
|
|
92
|
+
static dispatch_once_t once;
|
|
93
|
+
dispatch_once(&once, ^{
|
|
94
|
+
SDImageCacheConfig *config = SDImageCache.sharedImageCache.config;
|
|
95
|
+
for (NSString *name in FFFCacheLimitNames()) {
|
|
96
|
+
NSNumber *value = FFFCacheLimit(name);
|
|
97
|
+
if (value) {
|
|
98
|
+
FFFSetCacheLimit(config, name, value);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
80
103
|
|
|
81
|
-
|
|
104
|
+
@implementation FFFastImageModule
|
|
82
105
|
|
|
83
|
-
//
|
|
84
|
-
//
|
|
106
|
+
// React Native finds the module through codegenConfig's ios.modulesProvider
|
|
107
|
+
// (in the app's RCTAppDependencyProvider), as it finds the view through
|
|
108
|
+
// componentProvider, so it isn't registered with RCT_EXPORT_MODULE.
|
|
109
|
+
+ (NSString *)moduleName
|
|
110
|
+
{
|
|
111
|
+
return @"FastImageModule";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// The app's cache limits, before a preload (views apply them too).
|
|
85
115
|
+ (void)initialize
|
|
86
116
|
{
|
|
87
|
-
if (self
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
SDImageCacheConfig *config = SDImageCache.sharedImageCache.config;
|
|
91
|
-
for (NSString *name in FFFCacheLimitNames()) {
|
|
92
|
-
NSNumber *value = FFFCacheLimit(name);
|
|
93
|
-
if (value) {
|
|
94
|
-
FFFSetCacheLimit(config, name, value);
|
|
95
|
-
}
|
|
117
|
+
if (self == [FFFastImageModule class]) {
|
|
118
|
+
FFFApplyCacheLimits();
|
|
96
119
|
}
|
|
97
120
|
}
|
|
98
121
|
|
|
99
|
-
- (
|
|
100
|
-
|
|
122
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
123
|
+
{
|
|
124
|
+
return std::make_shared<facebook::react::NativeFastImageModuleSpecJSI>(params);
|
|
101
125
|
}
|
|
102
126
|
|
|
103
|
-
RCT_EXPORT_VIEW_PROPERTY(source, FFFastImageSource)
|
|
104
|
-
RCT_EXPORT_VIEW_PROPERTY(sources, FFFastImageSourceArray)
|
|
105
|
-
RCT_EXPORT_VIEW_PROPERTY(defaultSource, UIImage)
|
|
106
|
-
RCT_EXPORT_VIEW_PROPERTY(resizeMode, FFFResizeMode)
|
|
107
|
-
RCT_EXPORT_VIEW_PROPERTY(recyclingKey, NSString)
|
|
108
|
-
RCT_EXPORT_VIEW_PROPERTY(loopCount, NSInteger)
|
|
109
|
-
RCT_EXPORT_VIEW_PROPERTY(imageRendering, NSString)
|
|
110
|
-
RCT_EXPORT_VIEW_PROPERTY(paused, BOOL)
|
|
111
|
-
RCT_EXPORT_VIEW_PROPERTY(transitionDuration, double)
|
|
112
|
-
RCT_EXPORT_VIEW_PROPERTY(transitionBetweenImages, BOOL)
|
|
113
|
-
RCT_EXPORT_VIEW_PROPERTY(transitionSkipOnCacheHit, NSString)
|
|
114
|
-
RCT_EXPORT_VIEW_PROPERTY(downsample, BOOL)
|
|
115
|
-
RCT_EXPORT_VIEW_PROPERTY(blurRadius, CGFloat)
|
|
116
|
-
RCT_EXPORT_VIEW_PROPERTY(trackProgress, BOOL)
|
|
117
|
-
RCT_EXPORT_VIEW_PROPERTY(onFastImageLoadStart, RCTDirectEventBlock)
|
|
118
|
-
RCT_EXPORT_VIEW_PROPERTY(onFastImageProgress, RCTDirectEventBlock)
|
|
119
|
-
RCT_EXPORT_VIEW_PROPERTY(onFastImageError, RCTDirectEventBlock)
|
|
120
|
-
RCT_EXPORT_VIEW_PROPERTY(onFastImageLoad, RCTDirectEventBlock)
|
|
121
|
-
RCT_EXPORT_VIEW_PROPERTY(onFastImageLoadEnd, RCTDirectEventBlock)
|
|
122
|
-
RCT_REMAP_VIEW_PROPERTY(tintColor, imageColor, UIColor)
|
|
123
127
|
|
|
124
128
|
// Preloads waiting to start, in the order they were added, and the number
|
|
125
129
|
// loading, across all preload calls. Like SDWebImagePrefetcher, at most
|
|
@@ -260,11 +264,12 @@ static NSDictionary *FFFFile(NSString *path)
|
|
|
260
264
|
// { ok, width, height } or { ok: false, error }. Never rejects. A source with
|
|
261
265
|
// memoryCache false is only stored on disk, without decoding it (its size
|
|
262
266
|
// comes from the header).
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
267
|
+
- (void)preload:(NSArray *)sourcesJSON
|
|
268
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
269
|
+
reject:(__unused RCTPromiseRejectBlock)reject
|
|
266
270
|
{
|
|
267
|
-
|
|
271
|
+
NSArray<FFFastImageSource *> *sources = [RCTConvert FFFastImageSourceArray:sourcesJSON];
|
|
272
|
+
// This runs on the module's queue; the queue state is only touched on
|
|
268
273
|
// the main queue.
|
|
269
274
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
270
275
|
NSMutableArray *results = [NSMutableArray arrayWithCapacity:sources.count];
|
|
@@ -293,7 +298,7 @@ RCT_EXPORT_METHOD(preload:(nonnull NSArray<FFFastImageSource *> *)sources
|
|
|
293
298
|
if (!source.memoryCache) {
|
|
294
299
|
// Not decoded (only its header is read, for the size), and not
|
|
295
300
|
// kept in memory, also when it comes from the disk cache.
|
|
296
|
-
|
|
301
|
+
context[SDWebImageContextImageForceDecodePolicy] = @(SDImageForceDecodePolicyNever);
|
|
297
302
|
context[SDWebImageContextStoreCacheType] = @(SDImageCacheTypeDisk);
|
|
298
303
|
}
|
|
299
304
|
FFFQueueLoad(source, options, [context copy], ^(UIImage *image, NSError *error) {
|
|
@@ -317,10 +322,11 @@ RCT_EXPORT_METHOD(preload:(nonnull NSArray<FFFastImageSource *> *)sources
|
|
|
317
322
|
// preloads' queue): { ok, path } or { ok: false, error }. Never rejects. With
|
|
318
323
|
// `cacheOnly`, or a cacheKey without a uri, it doesn't download. A local
|
|
319
324
|
// file is its own path.
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
325
|
+
- (void)getCachePath:(NSDictionary *)sourceJSON
|
|
326
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
327
|
+
reject:(__unused RCTPromiseRejectBlock)reject
|
|
323
328
|
{
|
|
329
|
+
FFFastImageSource *source = [RCTConvert FFFastImageSource:sourceJSON];
|
|
324
330
|
if (!source.url) {
|
|
325
331
|
NSString *key = FFFDiskCacheKey(source);
|
|
326
332
|
if (!key) {
|
|
@@ -351,8 +357,9 @@ RCT_EXPORT_METHOD(getCachePath:(FFFastImageSource *)source
|
|
|
351
357
|
// As a disk-only preload: not decoded, and not looked up in or kept in
|
|
352
358
|
// memory (an image in memory may not be on disk). It completes once
|
|
353
359
|
// the file is written.
|
|
354
|
-
SDWebImageOptions options = FFFPreloadOptions(source) |
|
|
360
|
+
SDWebImageOptions options = FFFPreloadOptions(source) | SDWebImageWaitStoreCache;
|
|
355
361
|
SDWebImageMutableContext *context = FFFPreloadContext(source);
|
|
362
|
+
context[SDWebImageContextImageForceDecodePolicy] = @(SDImageForceDecodePolicyNever);
|
|
356
363
|
context[SDWebImageContextQueryCacheType] = @(SDImageCacheTypeDisk);
|
|
357
364
|
context[SDWebImageContextStoreCacheType] = @(SDImageCacheTypeDisk);
|
|
358
365
|
FFFQueueLoad(source, options, [context copy], ^(UIImage *image, NSError *error) {
|
|
@@ -374,11 +381,12 @@ RCT_EXPORT_METHOD(getCachePath:(FFFastImageSource *)source
|
|
|
374
381
|
// It doesn't replace an image that's already cached (Glide can't on Android;
|
|
375
382
|
// a new image should get a new cacheKey), and doesn't store `web` sources
|
|
376
383
|
// (Android keeps them only in an HTTP cache).
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
384
|
+
- (void)writeToCache:(NSDictionary *)sourceJSON
|
|
385
|
+
file:(NSString *)file
|
|
386
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
387
|
+
reject:(__unused RCTPromiseRejectBlock)reject
|
|
381
388
|
{
|
|
389
|
+
FFFastImageSource *source = [RCTConvert FFFastImageSource:sourceJSON];
|
|
382
390
|
if (source.cacheControl == FFFCacheControlWeb) {
|
|
383
391
|
resolve(FFFFailure(@"Can't store cache: 'web' images (they're kept in an HTTP cache)"));
|
|
384
392
|
return;
|
|
@@ -421,24 +429,27 @@ RCT_EXPORT_METHOD(writeToCache:(FFFastImageSource *)source
|
|
|
421
429
|
}
|
|
422
430
|
|
|
423
431
|
// Changes cache limits at runtime and saves them, so they're used on the next
|
|
424
|
-
// launches too: a number (0 for no limit), or
|
|
425
|
-
// Info.plist or SDWebImage's default. A lower disk limit applies at once (what's
|
|
432
|
+
// launches too: a number (0 for no limit), or its name in `reset` (null in
|
|
433
|
+
// JS) to go back to the app's Info.plist or SDWebImage's default. A lower disk limit applies at once (what's
|
|
426
434
|
// over it is removed; the disk cache is trimmed to half of maxDiskSize when
|
|
427
435
|
// it's over), instead of when the app next goes to the background. Resolves
|
|
428
436
|
// with the limits in effect (0 for no limit), and diskSize: the bytes the disk
|
|
429
437
|
// cache uses now.
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
438
|
+
- (void)configureCache:(NSDictionary *)limits
|
|
439
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
440
|
+
reject:(__unused RCTPromiseRejectBlock)reject
|
|
433
441
|
{
|
|
434
442
|
SDImageCache *cache = SDImageCache.sharedImageCache;
|
|
435
443
|
SDImageCacheConfig *config = cache.config;
|
|
436
444
|
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
437
445
|
NSUInteger maxDiskSize = config.maxDiskSize;
|
|
438
446
|
NSTimeInterval maxDiskAge = config.maxDiskAge;
|
|
447
|
+
// The limits set to null in JS arrive as a list of names (a TurboModule
|
|
448
|
+
// leaves null values out of the dictionary).
|
|
449
|
+
NSArray *reset = [limits[@"reset"] isKindOfClass:NSArray.class] ? limits[@"reset"] : @[];
|
|
439
450
|
for (NSString *name in FFFCacheLimitNames()) {
|
|
440
451
|
id value = limits[name];
|
|
441
|
-
if (
|
|
452
|
+
if ([reset containsObject:name]) {
|
|
442
453
|
[defaults removeObjectForKey:FFFSavedCacheLimitKey(name)];
|
|
443
454
|
} else if ([value isKindOfClass:NSNumber.class]) {
|
|
444
455
|
[defaults setObject:value forKey:FFFSavedCacheLimitKey(name)];
|
|
@@ -466,13 +477,13 @@ RCT_EXPORT_METHOD(configureCache:(NSDictionary *)limits
|
|
|
466
477
|
}
|
|
467
478
|
}
|
|
468
479
|
|
|
469
|
-
|
|
480
|
+
- (void)clearMemoryCache:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject
|
|
470
481
|
{
|
|
471
482
|
[SDImageCache.sharedImageCache clearMemory];
|
|
472
483
|
resolve(@{@"ok": @YES});
|
|
473
484
|
}
|
|
474
485
|
|
|
475
|
-
|
|
486
|
+
- (void)clearDiskCache:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject
|
|
476
487
|
{
|
|
477
488
|
// And the HTTP cache of `cache: 'web'` images.
|
|
478
489
|
[FFFastImageSource.webURLCache removeAllCachedResponses];
|
|
@@ -4,15 +4,19 @@
|
|
|
4
4
|
#import <SDWebImage/SDWebImageDownloader.h>
|
|
5
5
|
|
|
6
6
|
#import <React/RCTComponent.h>
|
|
7
|
-
#import <React/RCTResizeMode.h>
|
|
8
7
|
|
|
9
8
|
#import "FFFastImageSource.h"
|
|
10
9
|
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
// objectFit, as CSS's object-fit.
|
|
11
|
+
typedef NS_ENUM(NSInteger, FFFObjectFit) {
|
|
12
|
+
FFFObjectFitCover,
|
|
13
|
+
FFFObjectFitContain,
|
|
14
|
+
FFFObjectFitFill,
|
|
15
|
+
// The image at its own size, or scaled down to fit if it's larger.
|
|
16
|
+
FFFObjectFitScaleDown,
|
|
17
|
+
// The image at its own size, whatever its size (cropped by the view).
|
|
18
|
+
FFFObjectFitNone,
|
|
19
|
+
};
|
|
16
20
|
|
|
17
21
|
@interface FFFastImageView : SDAnimatedImageView
|
|
18
22
|
|
|
@@ -23,7 +27,7 @@ static const FFFResizeMode FFFResizeModeNone = (FFFResizeMode) -2;
|
|
|
23
27
|
@property (nonatomic, copy) RCTDirectEventBlock onFastImageError;
|
|
24
28
|
@property (nonatomic, copy) RCTDirectEventBlock onFastImageLoad;
|
|
25
29
|
@property (nonatomic, copy) RCTDirectEventBlock onFastImageLoadEnd;
|
|
26
|
-
@property (nonatomic, assign)
|
|
30
|
+
@property (nonatomic, assign) FFFObjectFit objectFit;
|
|
27
31
|
@property (nonatomic, strong) FFFastImageSource *source;
|
|
28
32
|
// Several sources (2 or more) of the same image at different sizes: the view
|
|
29
33
|
// loads the one whose size is closest to its own.
|
|
@@ -51,10 +55,35 @@ static const FFFResizeMode FFFResizeModeNone = (FFFResizeMode) -2;
|
|
|
51
55
|
@property (nonatomic, assign) BOOL downsample;
|
|
52
56
|
// Blurs the loaded image by this radius, in points (0 is no blur).
|
|
53
57
|
@property (nonatomic, assign) CGFloat blurRadius;
|
|
58
|
+
// objectPosition, as CSS computes it: on each axis the image's left or top
|
|
59
|
+
// edge is at (view - image) * fraction + offset, in points.
|
|
60
|
+
@property (nonatomic, assign) CGFloat objectPositionX;
|
|
61
|
+
@property (nonatomic, assign) CGFloat objectPositionXOffset;
|
|
62
|
+
@property (nonatomic, assign) CGFloat objectPositionY;
|
|
63
|
+
@property (nonatomic, assign) CGFloat objectPositionYOffset;
|
|
64
|
+
|
|
65
|
+
// After an update's props are set: loads the image if they changed it (once
|
|
66
|
+
// the view has a size, when it needs one).
|
|
67
|
+
- (void) didSetProps;
|
|
68
|
+
|
|
69
|
+
// Keeps the view's mask (React Native's, for its rounded corners) on the box
|
|
70
|
+
// the view was laid out at, while objectPosition moves the view: after React
|
|
71
|
+
// Native sets or removes it.
|
|
72
|
+
- (void) updateMask;
|
|
73
|
+
|
|
74
|
+
// Stops for good, before the view is discarded: cancels the load and sends no
|
|
75
|
+
// more events, also for a load that already finished and is on its way to the
|
|
76
|
+
// main queue.
|
|
77
|
+
- (void) stop;
|
|
54
78
|
|
|
55
79
|
@end
|
|
56
80
|
|
|
57
81
|
// An error's description, with the HTTP status code when there is one.
|
|
58
82
|
FOUNDATION_EXTERN NSString *FFFErrorMessage(NSError *error);
|
|
59
83
|
|
|
84
|
+
// Applies the app's cache limits (saved by configureCache, or in its
|
|
85
|
+
// Info.plist) to SDWebImage's cache, once, before FastImage loads an image
|
|
86
|
+
// (in FFFastImageModule.mm).
|
|
87
|
+
FOUNDATION_EXTERN void FFFApplyCacheLimits(void);
|
|
88
|
+
|
|
60
89
|
|