-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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 (#38668)
Summary: Pull Request resolved: #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 Reviewed By: NickGerleman Differential Revision: D47873465 fbshipit-source-id: 1dbb36be409c04ce87b356d75503ec0cf88f1c5b
- Loading branch information
1 parent
6e3e6b5
commit 2b688f6
Showing
9 changed files
with
137 additions
and
29 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
39 changes: 39 additions & 0 deletions
39
...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,39 @@ | ||
/* | ||
* 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/ColorComponents.h> | ||
#include <cmath> | ||
|
||
namespace facebook::react { | ||
|
||
using Color = int32_t; | ||
|
||
namespace HostPlatformColor { | ||
static const facebook::react::Color UndefinedColor = | ||
std::numeric_limits<facebook::react::Color>::max(); | ||
} | ||
|
||
inline 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); | ||
} | ||
|
||
inline 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 |
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
39 changes: 39 additions & 0 deletions
39
...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,39 @@ | ||
/* | ||
* 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/ColorComponents.h> | ||
#include <cmath> | ||
|
||
namespace facebook::react { | ||
|
||
using Color = int32_t; | ||
|
||
namespace HostPlatformColor { | ||
static const facebook::react::Color UndefinedColor = | ||
std::numeric_limits<facebook::react::Color>::max(); | ||
} | ||
|
||
inline Color hostPlatformColorFromComponents(ColorComponents components) { | ||
float ratio = 255; | ||
return ((int)std::round(components.alpha * ratio) & 0xff) << 24 | | ||
((int)std::round(components.red * ratio) & 0xff) << 16 | | ||
((int)std::round(components.green * ratio) & 0xff) << 8 | | ||
((int)std::round(components.blue * ratio) & 0xff); | ||
} | ||
|
||
inline 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 |
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
39 changes: 39 additions & 0 deletions
39
...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,39 @@ | ||
/* | ||
* 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/ColorComponents.h> | ||
#include <cmath> | ||
|
||
namespace facebook::react { | ||
|
||
using Color = int32_t; | ||
|
||
namespace HostPlatformColor { | ||
static const facebook::react::Color UndefinedColor = | ||
std::numeric_limits<facebook::react::Color>::max(); | ||
} | ||
|
||
inline 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); | ||
} | ||
|
||
inline 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 |
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