mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
61b013e7ad
Summary: Allow modifying iOS image cache limits. Currently the image cache imposes some strict limits: [NSCache.totalCostLimit](https://developer.apple.com/documentation/foundation/nscache/1407672-totalcostlimit?language=objc) of 20MB. Single Image Size Limit of 2MB (bitmap size). This may not be enough for applications that make heavy use of images. With this commit it is possible to fine tune them to the applications need. This can be set for example in the App Delegate with: ```objc RCTSetImageCacheLimits(4*1024*1024, 200*1024*1024); ``` This would increase the single image size limit to 4 MB and the total cost limit to 200 MB. ## Changelog [iOS] [Added] - Allow modifying iOS image cache limits Pull Request resolved: https://github.com/facebook/react-native/pull/33554 Test Plan: There is no easy way to test this except adding the above snippet and checking via break points that the new limits are used. Reviewed By: cipolleschi Differential Revision: D35485914 Pulled By: cortinico fbshipit-source-id: 646cf7cab5ea5258d0d0d0bce6383317e27e4445
46 lines
1.2 KiB
Objective-C
46 lines
1.2 KiB
Objective-C
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import <UIKit/UIKit.h>
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import <React/RCTResizeMode.h>
|
|
|
|
@interface UIImage (React)
|
|
|
|
/**
|
|
* Memory bytes of the image with the default calculation of static image or GIF. Custom calculations of decoded bytes can be assigned manually.
|
|
*/
|
|
@property (nonatomic, assign) NSInteger reactDecodedImageBytes;
|
|
|
|
@end
|
|
|
|
/**
|
|
* Provides an interface to use for providing a image caching strategy.
|
|
*/
|
|
@protocol RCTImageCache <NSObject>
|
|
|
|
- (UIImage *)imageForUrl:(NSString *)url
|
|
size:(CGSize)size
|
|
scale:(CGFloat)scale
|
|
resizeMode:(RCTResizeMode)resizeMode;
|
|
|
|
- (void)addImageToCache:(UIImage *)image
|
|
URL:(NSString *)url
|
|
size:(CGSize)size
|
|
scale:(CGFloat)scale
|
|
resizeMode:(RCTResizeMode)resizeMode
|
|
response:(NSURLResponse *)response;
|
|
|
|
@end
|
|
|
|
@interface RCTImageCache : NSObject <RCTImageCache>
|
|
|
|
RCT_EXTERN void RCTSetImageCacheLimits(NSUInteger maxCachableDecodedImageSizeInBytes, NSUInteger imageCacheTotalCostLimit);
|
|
|
|
@end
|