-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic DisplayP3 color support (#42830)
Summary: This adds initial support for wide gamut (DisplayP3) colors to React Native iOS per the [RFC](react-native-community/discussions-and-proposals#738). It provides the ability to set the default color space to sRGB or DisplayP3 and provides the native code necessary to support `color()` function syntax per the [W3C CSS Color Module Level 4](https://www.w3.org/TR/css-color-4/#color-function) spec. It does _not_ yet support animations and requires additional JS code before fully supporting the `color()` function syntax. bypass-github-export-checks ## Changelog: [IOS] [ADDED] - Add basic DisplayP3 color support Pull Request resolved: #42830 Test Plan: ![Screenshot_20240131-100112](https://github.com/facebook/react-native/assets/1944151/bbd011b1-dab0-47d6-b341-74fa8fac6757) Follow test steps from #42831 to test support for `color()` function syntax. To globally change the default color space to DisplayP3 make the following changes to RNTester AppDelegate.mm: ```diff + #import <React/RCTConvert.h> - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // ... + RCTSetDefaultColorSpace(RCTColorSpaceDisplayP3); return [super application:application didFinishLaunchingWithOptions:launchOptions]; } ``` Reviewed By: javache Differential Revision: D53380407 Pulled By: cipolleschi fbshipit-source-id: 938523958f9021e8d98bdb1d4e254047e3ecdad7
- Loading branch information
1 parent
3b93f0e
commit a40bd8e
Showing
11 changed files
with
180 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/react-native/React/Fabric/Utils/RCTColorSpaceUtils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#import <React/RCTConvert.h> | ||
|
||
@interface RCTColorSpaceUtils : NSObject | ||
|
||
+ (void)applyDefaultColorSpace:(RCTColorSpace)colorSpace; | ||
|
||
@end |
23 changes: 23 additions & 0 deletions
23
packages/react-native/React/Fabric/Utils/RCTColorSpaceUtils.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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 "RCTColorSpaceUtils.h" | ||
|
||
#import <react/renderer/graphics/ColorComponents.h> | ||
|
||
@implementation RCTColorSpaceUtils | ||
|
||
+ (void)applyDefaultColorSpace:(RCTColorSpace)colorSpace | ||
{ | ||
facebook::react::ColorSpace cxxColorSpace = | ||
colorSpace == RCTColorSpaceSRGB ? facebook::react::ColorSpace::sRGB : facebook::react::ColorSpace::DisplayP3; | ||
|
||
RCTSetDefaultColorSpace(colorSpace); | ||
facebook::react::setDefaultColorSpace(cxxColorSpace); | ||
} | ||
|
||
@end |
23 changes: 23 additions & 0 deletions
23
packages/react-native/ReactCommon/react/renderer/graphics/ColorComponents.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include "ColorComponents.h" | ||
#include <mutex> | ||
|
||
namespace facebook::react { | ||
|
||
static ColorSpace defaultColorSpace = ColorSpace::sRGB; | ||
|
||
ColorSpace getDefaultColorSpace() { | ||
return defaultColorSpace; | ||
} | ||
|
||
void setDefaultColorSpace(ColorSpace newColorSpace) { | ||
defaultColorSpace = newColorSpace; | ||
} | ||
|
||
} // namespace facebook::react |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters