Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-native/Libraries/Image/RCTAnimatedImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
@property (nonatomic, assign, readonly) NSUInteger animatedImageFrameCount;
@property (nonatomic, assign, readonly) NSUInteger animatedImageLoopCount;

- (nullable UIImage *)animatedImageFrameAtIndex:(NSUInteger)index;
- (nullable RCTPlatformImage *)animatedImageFrameAtIndex:(NSUInteger)index; // [macOS]
- (NSTimeInterval)animatedImageDurationAtIndex:(NSUInteger)index;

@end

@interface RCTAnimatedImage : UIImage <RCTAnimatedImage>
@interface RCTAnimatedImage : RCTPlatformImage <RCTAnimatedImage> // [macOS]
// [macOS
// This is a known initializer for UIImage, but needs to be exposed publicly for macOS since
// this is not a known initializer for NSImage
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/Libraries/Image/RCTAnimatedImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ - (NSTimeInterval)animatedImageDurationAtIndex:(NSUInteger)index
return _frames[index].duration;
}

- (UIImage *)animatedImageFrameAtIndex:(NSUInteger)index
- (RCTPlatformImage *)animatedImageFrameAtIndex:(NSUInteger)index // [macOS]
{
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(_imageSource, index, NULL);
if (!imageRef) {
Expand All @@ -157,7 +157,7 @@ - (UIImage *)animatedImageFrameAtIndex:(NSUInteger)index
#if !TARGET_OS_OSX // [macOS]
UIImage *image = [[UIImage alloc] initWithCGImage:imageRef scale:_scale orientation:UIImageOrientationUp];
#else // [macOS
UIImage *image = [[NSImage alloc] initWithCGImage:imageRef size:CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef))];
NSImage *image = [[NSImage alloc] initWithCGImage:imageRef size:CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef))];
#endif // macOS]
CGImageRelease(imageRef);
return image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ - (nullable RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
partialLoadHandler:(RCTImageLoaderPartialLoadBlock)partialLoadHandler
completionHandler:(RCTImageLoaderCompletionBlock)completionHandler
{
UIImage *image = RCTImageFromLocalAssetURL(imageURL);
RCTPlatformImage *image = RCTImageFromLocalAssetURL(imageURL); // [macOS]
if (image) {
if (progressHandler) {
progressHandler(1, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

#import <React/RCTDefines.h>

RCT_EXTERN UIImage *RCTBlurredImageWithRadius(UIImage *inputImage, CGFloat radius);
RCT_EXTERN RCTPlatformImage *RCTBlurredImageWithRadius(RCTPlatformImage *inputImage, CGFloat radius); // [macOS]
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import <React/RCTUIKit.h> // [macOS]
#import <React/RCTUtils.h> // [macOS]

UIImage *RCTBlurredImageWithRadius(UIImage *inputImage, CGFloat radius)
RCTPlatformImage *RCTBlurredImageWithRadius(RCTPlatformImage *inputImage, CGFloat radius) // [macOS]
{
CGImageRef imageRef = UIImageGetCGImageRef(inputImage); // [macOS]
CGFloat imageScale = UIImageGetScale(inputImage); // [macOS]
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/Libraries/Image/RCTImageCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#import <React/RCTResizeMode.h>

@interface UIImage (React)
@interface RCTPlatformImage (React) // [macOS]

/**
* Memory bytes of the image with the default calculation of static image or GIF. Custom calculations of decoded bytes
Expand All @@ -25,9 +25,9 @@
*/
@protocol RCTImageCache <NSObject>

- (UIImage *)imageForUrl:(NSString *)url size:(CGSize)size scale:(CGFloat)scale resizeMode:(RCTResizeMode)resizeMode;
- (RCTPlatformImage *)imageForUrl:(NSString *)url size:(CGSize)size scale:(CGFloat)scale resizeMode:(RCTResizeMode)resizeMode; // [macOS]

- (void)addImageToCache:(UIImage *)image
- (void)addImageToCache:(RCTPlatformImage *)image // [macOS]
URL:(NSString *)url
size:(CGSize)size
scale:(CGFloat)scale
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/Libraries/Image/RCTImageCache.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ - (void)clearCache
}
#endif // [macOS]

- (void)addImageToCache:(UIImage *)image forKey:(NSString *)cacheKey
- (void)addImageToCache:(RCTPlatformImage *)image forKey:(NSString *)cacheKey // [macOS]
{
if (!image) {
return;
Expand All @@ -82,7 +82,7 @@ - (void)addImageToCache:(UIImage *)image forKey:(NSString *)cacheKey
}
}

- (UIImage *)imageForUrl:(NSString *)url size:(CGSize)size scale:(CGFloat)scale resizeMode:(RCTResizeMode)resizeMode
- (RCTPlatformImage *)imageForUrl:(NSString *)url size:(CGSize)size scale:(CGFloat)scale resizeMode:(RCTResizeMode)resizeMode // [macOS]
{
NSString *cacheKey = RCTCacheKeyForImage(url, size, scale, resizeMode);
@synchronized(_cacheStaleTimes) {
Expand All @@ -99,7 +99,7 @@ - (UIImage *)imageForUrl:(NSString *)url size:(CGSize)size scale:(CGFloat)scale
return [_decodedImageCache objectForKey:cacheKey];
}

- (void)addImageToCache:(UIImage *)image
- (void)addImageToCache:(RCTPlatformImage *)image // [macOS]
URL:(NSString *)url
size:(CGSize)size
scale:(CGFloat)scale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ @implementation RCTImageEditingManager

[[_moduleRegistry moduleForName:"ImageLoader"]
loadImageWithURLRequest:imageRequest
callback:^(NSError *error, UIImage *image) {
callback:^(NSError *error, RCTPlatformImage *image) { // [macOS]
if (error) {
errorCallback(@[ RCTJSErrorFromNSError(error) ]);
return;
Expand All @@ -70,7 +70,7 @@ @implementation RCTImageEditingManager
CGSize targetSize = rect.size;
CGRect targetRect = {{-rect.origin.x, -rect.origin.y}, image.size};
CGAffineTransform transform = RCTTransformFromTargetRect(image.size, targetRect);
UIImage *croppedImage = RCTTransformImage(image, targetSize, UIImageGetScale(image), transform); // [macOS]
RCTPlatformImage *croppedImage = RCTTransformImage(image, targetSize, UIImageGetScale(image), transform); // [macOS]

// Scale image
if (cropDataCopy.displaySize()) {
Expand Down
36 changes: 18 additions & 18 deletions packages/react-native/Libraries/Image/RCTImageLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

using namespace facebook::react;

static NSInteger RCTImageBytesForImage(UIImage *image)
static NSInteger RCTImageBytesForImage(RCTPlatformImage *image) // [macOS]
{
CGFloat imageScale = 1.0;
#if !TARGET_OS_OSX // [macOS] no .scale prop on NSImage
Expand Down Expand Up @@ -89,7 +89,7 @@ @interface RCTImageLoader () <NativeImageLoaderIOSSpec, RCTImageLoaderWithAttrib

@end

@implementation UIImage (React)
@implementation RCTPlatformImage (React) // [macOS]

- (NSInteger)reactDecodedImageBytes
{
Expand Down Expand Up @@ -345,7 +345,7 @@ - (void)setImageCache:(id<RCTImageCache>)cache
return nil;
}

static UIImage *RCTResizeImageIfNeeded(UIImage *image, CGSize size, CGFloat scale, RCTResizeMode resizeMode)
static RCTPlatformImage *RCTResizeImageIfNeeded(RCTPlatformImage *image, CGSize size, CGFloat scale, RCTResizeMode resizeMode) // [macOS]
{
if (CGSizeEqualToSize(size, CGSizeZero) || CGSizeEqualToSize(image.size, CGSizeZero) ||
CGSizeEqualToSize(image.size, size)) {
Expand Down Expand Up @@ -419,7 +419,7 @@ - (nullable RCTImageLoaderCancellationBlock)loadImageWithURLRequest:(NSURLReques
attribution:{}
progressBlock:progressBlock
partialLoadBlock:partialLoadBlock
completionBlock:^(NSError *error, UIImage *image, id metadata) {
completionBlock:^(NSError *error, RCTPlatformImage *image, id metadata) { // [macOS]
completionBlock(error, image);
}];
return ^{
Expand Down Expand Up @@ -555,7 +555,7 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req
}

if (cacheResult && partialLoadHandler) {
UIImage *image = [[self imageCache] imageForUrl:request.URL.absoluteString
RCTPlatformImage *image = [[self imageCache] imageForUrl:request.URL.absoluteString // [macOS]
size:size
scale:scale
resizeMode:resizeMode];
Expand All @@ -577,7 +577,7 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req

// If we've received an image, we should try to set it synchronously,
// if it's data, do decoding on a background thread.
if (RCTIsMainQueue() && ![imageOrData isKindOfClass:[UIImage class]]) {
if (RCTIsMainQueue() && ![imageOrData isKindOfClass:[RCTPlatformImage class]]) { // [macOS]
// Most loaders do not return on the main thread, so caller is probably not
// expecting it, and may do expensive post-processing in the callback
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
Expand Down Expand Up @@ -608,7 +608,7 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req
attribution:attributionCopy
progressHandler:progressHandler
partialLoadHandler:partialLoadHandler
completionHandler:^(NSError *error, UIImage *image, id metadata) {
completionHandler:^(NSError *error, RCTPlatformImage *image, id metadata) { // [macOS]
completionHandler(error, image, metadata, nil);
}];
}
Expand All @@ -618,7 +618,7 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req
resizeMode:resizeMode
progressHandler:progressHandler
partialLoadHandler:partialLoadHandler
completionHandler:^(NSError *error, UIImage *image) {
completionHandler:^(NSError *error, RCTPlatformImage *image) { // [macOS]
completionHandler(error, image, nil, nil);
}];
return [[RCTImageURLLoaderRequest alloc] initWithRequestId:nil imageURL:request.URL cancellationBlock:cb];
Expand Down Expand Up @@ -649,7 +649,7 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req
attribution:attributionCopy
progressHandler:progressHandler
partialLoadHandler:partialLoadHandler
completionHandler:^(NSError *error, UIImage *image, id metadata) {
completionHandler:^(NSError *error, RCTPlatformImage *image, id metadata) { // [macOS]
completionHandler(error, image, metadata, nil);
}];
cancelLoadLocal = loaderRequest.cancellationBlock;
Expand All @@ -660,15 +660,15 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req
resizeMode:resizeMode
progressHandler:progressHandler
partialLoadHandler:partialLoadHandler
completionHandler:^(NSError *error, UIImage *image) {
completionHandler:^(NSError *error, RCTPlatformImage *image) { // [macOS]
completionHandler(error, image, nil, nil);
}];
}
[cancelLoadLock lock];
cancelLoad = cancelLoadLocal;
[cancelLoadLock unlock];
} else {
UIImage *image;
RCTPlatformImage *image; // [macOS]
if (cacheResult) {
image = [[strongSelf imageCache] imageForUrl:request.URL.absoluteString
size:size
Expand Down Expand Up @@ -858,15 +858,15 @@ - (RCTImageURLLoaderRequest *)loadImageWithURLRequest:(NSURLRequest *)imageURLRe
return;
}

if (!imageOrData || [imageOrData isKindOfClass:[UIImage class]]) {
if (!imageOrData || [imageOrData isKindOfClass:[RCTPlatformImage class]]) { // [macOS]
[cancelLoadLock lock];
cancelLoad = nil;
[cancelLoadLock unlock];
completionBlock(error, imageOrData, imageMetadata);
return;
}

RCTImageLoaderCompletionBlock decodeCompletionHandler = ^(NSError *error_, UIImage *image) {
RCTImageLoaderCompletionBlock decodeCompletionHandler = ^(NSError *error_, RCTPlatformImage *image) { // [macOS]
if (cacheResult && image) {
// Store decoded image in cache
[[strongSelf imageCache] addImageToCache:image
Expand Down Expand Up @@ -971,7 +971,7 @@ - (RCTImageLoaderCancellationBlock)decodeImageData:(NSData *)data
}

auto cancelled = std::make_shared<std::atomic<int>>(0);
void (^completionHandler)(NSError *, UIImage *) = ^(NSError *error, UIImage *image) {
void (^completionHandler)(NSError *, RCTPlatformImage *) = ^(NSError *error, RCTPlatformImage *image) { // [macOS]
if (RCTIsMainQueue()) {
// Most loaders do not return on the main thread, so caller is probably not
// expecting it, and may do expensive post-processing in the callback
Expand Down Expand Up @@ -1006,7 +1006,7 @@ - (RCTImageLoaderCancellationBlock)decodeImageData:(NSData *)data
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if (!std::atomic_load(cancelled.get())) {
// Decompress the image data (this may be CPU and memory intensive)
UIImage *image = RCTDecodeImageWithData(data, size, scale, resizeMode);
RCTPlatformImage *image = RCTDecodeImageWithData(data, size, scale, resizeMode); // [macOS]

#if !TARGET_OS_OSX && RCT_DEV // [macOS]
CGSize imagePixelSize = RCTSizeInPixels(image.size, UIImageGetScale(image)); // [macOS]
Expand Down Expand Up @@ -1101,7 +1101,7 @@ - (RCTImageLoaderCancellationBlock)getImageSizeForURLRequest:(NSURLRequest *)ima
break;
}
} else {
UIImage *image = imageOrData;
RCTPlatformImage *image = imageOrData; // [macOS]
#if !TARGET_OS_OSX // [macOS]
CGFloat imageScale = image.scale;
#else // [macOS
Expand Down Expand Up @@ -1195,7 +1195,7 @@ - (id)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequestDelegate
{
__block RCTImageLoaderCancellationBlock requestToken;
requestToken = [self loadImageWithURLRequest:request
callback:^(NSError *error, UIImage *image) {
callback:^(NSError *error, RCTPlatformImage *image) { // [macOS]
if (error) {
[delegate URLRequest:requestToken didCompleteWithError:error];
return;
Expand Down Expand Up @@ -1305,7 +1305,7 @@ - (void)cancelRequest:(id)requestToken
}
progressBlock:nil
partialLoadBlock:nil
completionBlock:^(NSError *error, UIImage *image, id completionMetadata) {
completionBlock:^(NSError *error, RCTPlatformImage *image, id completionMetadata) { // [macOS]
if (error) {
reject(@"E_PREFETCH_FAILURE", nil, error);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RCT_EXTERN void RCTEnableImageStoreManagerStorageQueue(BOOL enabled);
* Convenience method to store an image directly (image is converted to data
* internally, so any metadata such as scale or orientation will be lost).
*/
- (void)storeImage:(UIImage *)image withBlock:(void (^)(NSString *imageTag))block;
- (void)storeImage:(RCTPlatformImage *)image withBlock:(void (^)(NSString *imageTag))block; // [macOS]

@end

Expand All @@ -36,9 +36,9 @@ RCT_EXTERN void RCTEnableImageStoreManagerStorageQueue(BOOL enabled);
/**
* These methods are deprecated - use the data-based alternatives instead.
*/
- (NSString *)storeImage:(UIImage *)image __deprecated;
- (UIImage *)imageForTag:(NSString *)imageTag __deprecated;
- (void)getImageForTag:(NSString *)imageTag withBlock:(void (^)(UIImage *image))block __deprecated;
- (NSString *)storeImage:(RCTPlatformImage *)image __deprecated; // [macOS]
- (RCTPlatformImage *)imageForTag:(NSString *)imageTag __deprecated; // [macOS]
- (void)getImageForTag:(NSString *)imageTag withBlock:(void (^)(RCTPlatformImage *image))block __deprecated; // [macOS]

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ - (void)getImageDataForTag:(NSString *)imageTag withBlock:(void (^)(NSData *imag
});
}

- (void)storeImage:(UIImage *)image withBlock:(void (^)(NSString *imageTag))block
- (void)storeImage:(RCTPlatformImage *)image withBlock:(void (^)(NSString *imageTag))block // [macOS]
{
RCTAssertParam(block);
dispatch_async([self _getAsyncQueue], ^{
Expand Down Expand Up @@ -236,7 +236,7 @@ - (void)cancelRequest:(id)requestToken

@implementation RCTImageStoreManager (Deprecated)

- (NSString *)storeImage:(UIImage *)image
- (NSString *)storeImage:(RCTPlatformImage *)image // [macOS]
{
RCTAssertMainQueue();
RCTLogWarn(
Expand All @@ -248,7 +248,7 @@ - (NSString *)storeImage:(UIImage *)image
return imageTag;
}

- (UIImage *)imageForTag:(NSString *)imageTag
- (RCTPlatformImage *)imageForTag:(NSString *)imageTag // [macOS]
{
RCTAssertMainQueue();
RCTLogWarn(
Expand All @@ -260,7 +260,7 @@ - (UIImage *)imageForTag:(NSString *)imageTag
return UIImageWithData(imageData); // [macOS]
}

- (void)getImageForTag:(NSString *)imageTag withBlock:(void (^)(UIImage *image))block
- (void)getImageForTag:(NSString *)imageTag withBlock:(void (^)(RCTPlatformImage *image))block // [macOS]
{
RCTAssertParam(block);
dispatch_async([self _getAsyncQueue], ^{
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/Libraries/Image/RCTImageURLLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
NS_ASSUME_NONNULL_BEGIN

typedef void (^RCTImageLoaderProgressBlock)(int64_t progress, int64_t total);
typedef void (^RCTImageLoaderPartialLoadBlock)(UIImage *image);
typedef void (^RCTImageLoaderCompletionBlock)(NSError *_Nullable error, UIImage *_Nullable image);
typedef void (^RCTImageLoaderPartialLoadBlock)(RCTPlatformImage *image); // [macOS]
typedef void (^RCTImageLoaderCompletionBlock)(NSError *_Nullable error, RCTPlatformImage *_Nullable image); // [macOS]
// Metadata is passed as a id in an additional parameter because there are forks of RN without this parameter,
// and the complexity of RCTImageLoader would make using protocols here difficult to typecheck.
typedef void (^RCTImageLoaderCompletionBlockWithMetadata)(
NSError *_Nullable error,
UIImage *_Nullable image,
RCTPlatformImage *_Nullable image, // [macOS]
id _Nullable metadata);
typedef dispatch_block_t RCTImageLoaderCancellationBlock;

Expand Down
10 changes: 5 additions & 5 deletions packages/react-native/Libraries/Image/RCTImageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ RCT_EXTERN BOOL RCTUpscalingRequired(
* width/height of the returned image is guaranteed to be >= destSize.
* Pass a destSize of CGSizeZero to decode the image at its original size.
*/
RCT_EXTERN UIImage *__nullable
RCT_EXTERN RCTPlatformImage *__nullable // [macOS]
RCTDecodeImageWithData(NSData *data, CGSize destSize, CGFloat destScale, RCTResizeMode resizeMode);

/**
Expand All @@ -76,15 +76,15 @@ RCT_EXTERN NSDictionary<NSString *, id> *__nullable RCTGetImageMetadata(NSData *
* conversion, with 1.0 being maximum quality. It has no effect for images
* using PNG compression.
*/
RCT_EXTERN NSData *__nullable RCTGetImageData(UIImage *image, float quality);
RCT_EXTERN NSData *__nullable RCTGetImageData(RCTPlatformImage *image, float quality); // [macOS]

/**
* This function transforms an image. `destSize` is the size of the final image,
* and `destScale` is its scale. The `transform` argument controls how the
* source image will be mapped to the destination image.
*/
RCT_EXTERN UIImage *__nullable
RCTTransformImage(UIImage *image, CGSize destSize, CGFloat destScale, CGAffineTransform transform);
RCT_EXTERN RCTPlatformImage *__nullable // [macOS]
RCTTransformImage(RCTPlatformImage *image, CGSize destSize, CGFloat destScale, CGAffineTransform transform); // [macOS]

/*
* Return YES if image has an alpha component
Expand All @@ -94,6 +94,6 @@ RCT_EXTERN BOOL RCTImageHasAlpha(CGImageRef image);
/*
* Return YES if image has an alpha component
*/
RCT_EXTERN BOOL RCTUIImageHasAlpha(UIImage *image); // [macOS]
RCT_EXTERN BOOL RCTUIImageHasAlpha(RCTPlatformImage *image); // [macOS]

NS_ASSUME_NONNULL_END
Loading
Loading