forked from microsoft/react-native-macos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract underlying Color implementation (facebook#38668)
Summary: Pull Request resolved: facebook#38668 On other platforms (e.g., react-native-windows), it's possible that platform colors may not be efficiently represented as int32_t values. In the case of react-native-windows, Color can either be an ARGB value or a list of fallback strings for platform colors. This change should decouple how platforms represent color values, allowing them to manage how they are used at the point they are used. ## Changelog: [General] [Added] - Support customization of underlying Color representation in out-of-tree platforms Differential Revision: D47873465 fbshipit-source-id: 283ef5d44f512fbd228e68aff88f11957388a68d
- Loading branch information
1 parent
52196a6
commit cb7a200
Showing
9 changed files
with
77 additions
and
23 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
31 changes: 31 additions & 0 deletions
31
packages/react-native/ReactCommon/react/renderer/graphics/DefaultColor.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,31 @@ | ||
/* | ||
* 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 | ||
|
||
namespace facebook::react { | ||
|
||
using Color = int32_t; | ||
|
||
Color hostPlatformColorFromComponents(ColorComponents components) { | ||
float ratio = 255; | ||
return ((int)round(components.alpha * ratio) & 0xff) << 24 | | ||
((int)round(components.red * ratio) & 0xff) << 16 | | ||
((int)round(components.green * ratio) & 0xff) << 8 | | ||
((int)round(components.blue * ratio) & 0xff); | ||
} | ||
|
||
ColorComponents colorComponentsFromHostPlatformColor(Color color) { | ||
float ratio = 255; | ||
return ColorComponents{ | ||
(float)((color >> 16) & 0xff) / ratio, | ||
(float)((color >> 8) & 0xff) / ratio, | ||
(float)((color >> 0) & 0xff) / ratio, | ||
(float)((color >> 24) & 0xff) / ratio}; | ||
} | ||
|
||
} // namespace facebook::react |
10 changes: 10 additions & 0 deletions
10
...mmon/react/renderer/graphics/platform/android/react/renderer/graphics/HostPlatformColor.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,10 @@ | ||
/* | ||
* 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 | ||
|
||
#include <react/renderer/graphics/DefaultColor.h> |
10 changes: 10 additions & 0 deletions
10
...ctCommon/react/renderer/graphics/platform/cxx/react/renderer/graphics/HostPlatformColor.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,10 @@ | ||
/* | ||
* 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 | ||
|
||
#include <react/renderer/graphics/DefaultColor.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
10 changes: 10 additions & 0 deletions
10
...ctCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.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,10 @@ | ||
/* | ||
* 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 | ||
|
||
#include <react/renderer/graphics/DefaultColor.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