Generalized image decoding and resizing logic

Summary:
public

Standardises the image decoding logic for all image sources, meaning we get the benefits of efficient downscaling of images from all sources, not just ALAssets.

Reviewed By: javache

Differential Revision: D2647083

fb-gh-sync-id: e41456f838e4c6ab709b1c1523f651a86ff6e623
This commit is contained in:
Nick Lockwood
2016-01-20 11:03:22 -08:00
committed by facebook-github-bot-5
parent 9b87e6c860
commit 21fcbbc32c
30 changed files with 510 additions and 379 deletions

View File

@@ -40,6 +40,9 @@ RCT_EXTERN CGFloat RCTRoundPixelValue(CGFloat value);
RCT_EXTERN CGFloat RCTCeilPixelValue(CGFloat value);
RCT_EXTERN CGFloat RCTFloorPixelValue(CGFloat value);
// Convert a size in points to pixels, rounded up to the nearest integral size
RCT_EXTERN CGSize RCTSizeInPixels(CGSize pointSize, CGFloat scale);
// Method swizzling
RCT_EXTERN void RCTSwapClassMethods(Class cls, SEL original, SEL replacement);
RCT_EXTERN void RCTSwapInstanceMethods(Class cls, SEL original, SEL replacement);
@@ -78,9 +81,6 @@ RCT_EXTERN UIAlertView *RCTAlertView(NSString *title,
NSString *cancelButtonTitle,
NSArray<NSString *> *otherButtonTitles);
// Return YES if image has an alpha component
RCT_EXTERN BOOL RCTImageHasAlpha(CGImageRef image);
// Create an NSError in the RCTErrorDomain
RCT_EXTERN NSError *RCTErrorWithMessage(NSString *message);

View File

@@ -219,7 +219,13 @@ CGSize RCTScreenSize()
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
RCTExecuteOnMainThread(^{
size = [UIScreen mainScreen].bounds.size;
if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending) {
CGSize pixelSize = [UIScreen mainScreen].nativeBounds.size;
CGFloat scale = RCTScreenScale();
size = (CGSize){pixelSize.width / scale, pixelSize.height / scale};
} else {
size = [UIScreen mainScreen].bounds.size;
}
}, YES);
});
@@ -244,6 +250,14 @@ CGFloat RCTFloorPixelValue(CGFloat value)
return floor(value * scale) / scale;
}
CGSize RCTSizeInPixels(CGSize pointSize, CGFloat scale)
{
return (CGSize){
ceil(pointSize.width * scale),
ceil(pointSize.height * scale),
};
}
void RCTSwapClassMethods(Class cls, SEL original, SEL replacement)
{
Method originalMethod = class_getClassMethod(cls, original);
@@ -401,18 +415,6 @@ UIAlertView *RCTAlertView(NSString *title,
return alertView;
}
BOOL RCTImageHasAlpha(CGImageRef image)
{
switch (CGImageGetAlphaInfo(image)) {
case kCGImageAlphaNone:
case kCGImageAlphaNoneSkipLast:
case kCGImageAlphaNoneSkipFirst:
return NO;
default:
return YES;
}
}
NSError *RCTErrorWithMessage(NSString *message)
{
NSDictionary<NSString *, id> *errorInfo = @{NSLocalizedDescriptionKey: message};