Skip to content

Instantly share code, notes, and snippets.

@canpoyrazoglu
Created January 3, 2021 11:30
Show Gist options
  • Save canpoyrazoglu/e85a47701a7be291dbd05372e8e5f76f to your computer and use it in GitHub Desktop.
Save canpoyrazoglu/e85a47701a7be291dbd05372e8e5f76f to your computer and use it in GitHub Desktop.
React Native patch to display all images and colors in P3 color space on iOS (use patch-package npm package to apply)
diff --git a/node_modules/react-native/Libraries/Image/RCTImageUtils.m b/node_modules/react-native/Libraries/Image/RCTImageUtils.m
index 899bfe4..33133c3 100644
--- a/node_modules/react-native/Libraries/Image/RCTImageUtils.m
+++ b/node_modules/react-native/Libraries/Image/RCTImageUtils.m
@@ -308,13 +308,26 @@ BOOL RCTUpscalingRequired(CGSize sourceSize, CGFloat sourceScale,
if (!imageRef) {
return nil;
}
+ if (@available(iOS 10, *)) {
+ // Return all images in P3 color space
+ CGImageRef p3Image = CGImageCreateCopyWithColorSpace(imageRef, CGColorSpaceCreateWithName(kCGColorSpaceDisplayP3));
+ UIImage *image = [UIImage imageWithCGImage:p3Image
+ scale:destScale
+ orientation:UIImageOrientationUp];
+ CGImageRelease(imageRef);
+ CGImageRelease(p3Image);
+ return image;
+ } else {
+ // Return image
+ UIImage *image = [UIImage imageWithCGImage:imageRef
+ scale:destScale
+ orientation:UIImageOrientationUp];
+ CGImageRelease(imageRef);
+ return image;
+ }
+
+
- // Return image
- UIImage *image = [UIImage imageWithCGImage:imageRef
- scale:destScale
- orientation:UIImageOrientationUp];
- CGImageRelease(imageRef);
- return image;
}
NSDictionary<NSString *, id> *__nullable RCTGetImageMetadata(NSData *data)
diff --git a/node_modules/react-native/React/Base/RCTConvert.m b/node_modules/react-native/React/Base/RCTConvert.m
index 6de135b..02ed169 100644
--- a/node_modules/react-native/React/Base/RCTConvert.m
+++ b/node_modules/react-native/React/Base/RCTConvert.m
@@ -834,7 +834,7 @@ + (UIColor *)UIColor:(id)json
if ([json isKindOfClass:[NSArray class]]) {
NSArray *components = [self NSNumberArray:json];
CGFloat alpha = components.count > 3 ? [self CGFloat:components[3]] : 1.0;
- return [UIColor colorWithRed:[self CGFloat:components[0]]
+ return [UIColor colorWithDisplayP3Red:[self CGFloat:components[0]]
green:[self CGFloat:components[1]]
blue:[self CGFloat:components[2]]
alpha:alpha];
@@ -844,7 +844,7 @@ + (UIColor *)UIColor:(id)json
CGFloat r = ((argb >> 16) & 0xFF) / 255.0;
CGFloat g = ((argb >> 8) & 0xFF) / 255.0;
CGFloat b = (argb & 0xFF) / 255.0;
- return [UIColor colorWithRed:r green:g blue:b alpha:a];
+ return [UIColor colorWithDisplayP3Red:r green:g blue:b alpha:a];
} else if ([json isKindOfClass:[NSDictionary class]]) {
NSDictionary *dictionary = json;
id value = nil;
diff --git a/node_modules/react-native/scripts/.packager.env b/node_modules/react-native/scripts/.packager.env
new file mode 100644
index 0000000..361f5fb
--- /dev/null
+++ b/node_modules/react-native/scripts/.packager.env
@@ -0,0 +1 @@
+export RCT_METRO_PORT=8081
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment