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
32 changes: 19 additions & 13 deletions Libraries/Image/RCTImageLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#import <React/RCTLog.h>
#import <React/RCTNetworking.h>
#import <React/RCTUtils.h>
#import <React/RCTUIKit.h> // TODO(macOS GH#774)

#import "RCTImagePlugins.h"

Expand Down Expand Up @@ -54,7 +53,13 @@ static NSInteger RCTImageBytesForImage(UIImage *image)
#endif // [TODO(macOS GH#774)
}

#if TARGET_OS_OSX
#if TARGET_OS_OSX // [TODO(macOS GH#774)

/**
* Github #1611 - We can't depend on RCTUIKit here, because this file's podspec (React-RCTImage) doesn't
* take a dependency on RCTUIKit's pod `React-Core`. Let's just copy the methods we want to shim here
*/

static NSData *NSImageDataForFileType(NSImage *image, NSBitmapImageFileType fileType, NSDictionary<NSString *, id> *properties)
{
RCTAssert(image.representations.count == 1, @"Expected only a single representation since UIImage only supports one.");
Expand All @@ -67,7 +72,18 @@ static NSInteger RCTImageBytesForImage(UIImage *image)

return [imageRep representationUsingType:fileType properties:properties];
}
#endif // TARGET_OS_OSX


NSData *UIImagePNGRepresentation(NSImage *image) {
return NSImageDataForFileType(image, NSBitmapImageFileTypePNG, @{});
}

NSData *UIImageJPEGRepresentation(NSImage *image, CGFloat compressionQuality) {
return NSImageDataForFileType(image,
NSBitmapImageFileTypeJPEG,
@{NSImageCompressionFactor: @(compressionQuality)});
}
#endif // ]TODO(macOS GH#774)

static uint64_t monotonicTimeGetCurrentNanoseconds(void)
{
Expand Down Expand Up @@ -1145,20 +1161,10 @@ - (id)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequestDelegate
NSData *imageData = nil;
if (RCTUIImageHasAlpha(image)) { // TODO(macOS GH#774)
mimeType = @"image/png";
#if TARGET_OS_OSX
imageData = NSImageDataForFileType(image, NSBitmapImageFileTypePNG, @{});
#else
imageData = UIImagePNGRepresentation(image);
#endif // !TARGET_OS_OSX
} else {
mimeType = @"image/jpeg";
#if TARGET_OS_OSX
imageData = NSImageDataForFileType(image,
NSBitmapImageFileTypeJPEG,
@{NSImageCompressionFactor : @(1.0)});
#else
imageData = UIImageJPEGRepresentation(image, 1.0);
#endif // !TARGET_OS_OSX
}

NSURLResponse *response = [[NSURLResponse alloc] initWithURL:request.URL
Expand Down
2 changes: 1 addition & 1 deletion React/Base/macOS/RCTUIKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ CGImageRef UIImageGetCGImageRef(NSImage *image)
NSData *UIImageJPEGRepresentation(NSImage *image, CGFloat compressionQuality) {
return NSImageDataForFileType(image,
NSBitmapImageFileTypeJPEG,
@{NSImageCompressionFactor: @(1.0)});
@{NSImageCompressionFactor: @(compressionQuality)});
}

// UIBezierPath
Expand Down