Skip to content

Commit 7aeac42

Browse files
acoates-msfacebook-github-bot
authored andcommitted
Move isColorMeaningful to platform specific code (#31557)
Summary: `isColorMeaningful` is the only place in xplat code that currently uses `colorComponentsFromColor`, which assumes that a color is an RGBA value. When implementing `PlatformColor` for windows, where colors might be complex patterns or effects, I'd like to keep the details of `SharedColor` isolated within `SharedColor`. This change moves `isColorMeaningful` into `color.cpp`, where each platform can provide an implementation that takes into account its platform specific color capabilities. See microsoft/react-native-windows#7801 for an example of window's SharedColor which can be either an RGBA value, or a name of a native color/brush. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Internal] [Changed] - Move isColorMeaningful to platform specific code Pull Request resolved: #31557 Test Plan: This shouldn't change any of the code, its just moving the existing function - normal CI/automation should be plenty of validation. Reviewed By: JoshuaGross, sammy-SC Differential Revision: D28557698 Pulled By: mdvacca fbshipit-source-id: 2a94850fe9c5037598107e1307f4153cee6491fb
1 parent ffa533a commit 7aeac42

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

ReactCommon/react/renderer/components/view/ViewShadowNode.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ ViewShadowNode::ViewShadowNode(
2828
initialize();
2929
}
3030

31-
static bool isColorMeaningful(SharedColor const &color) noexcept {
32-
if (!color) {
33-
return false;
34-
}
35-
36-
return colorComponentsFromColor(color).alpha > 0;
37-
}
38-
3931
void ViewShadowNode::initialize() noexcept {
4032
auto &viewProps = static_cast<ViewProps const &>(*props_);
4133

ReactCommon/react/renderer/graphics/platform/cxx/react/renderer/graphics/Color.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
namespace facebook {
1111
namespace react {
1212

13+
bool isColorMeaningful(SharedColor const &color) noexcept {
14+
if (!color) {
15+
return false;
16+
}
17+
18+
return colorComponentsFromColor(color).alpha > 0;
19+
}
20+
1321
SharedColor colorFromComponents(ColorComponents components) {
1422
float ratio = 255;
1523
return SharedColor(

ReactCommon/react/renderer/graphics/platform/cxx/react/renderer/graphics/Color.h

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class SharedColor {
5959
Color color_;
6060
};
6161

62+
bool isColorMeaningful(SharedColor const &color) noexcept;
6263
SharedColor colorFromComponents(ColorComponents components);
6364
ColorComponents colorComponentsFromColor(SharedColor color);
6465

ReactCommon/react/renderer/graphics/platform/ios/Color.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
namespace facebook {
1212
namespace react {
1313

14+
bool isColorMeaningful(SharedColor const &color) noexcept {
15+
if (!color) {
16+
return false;
17+
}
18+
19+
return colorComponentsFromColor(color).alpha > 0;
20+
}
21+
1422
SharedColor colorFromComponents(ColorComponents components) {
1523
float ratio = 255;
1624
return SharedColor(

ReactCommon/react/renderer/graphics/platform/ios/Color.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using Color = int32_t;
2020

2121
using SharedColor = better::optional<Color>;
2222

23+
bool isColorMeaningful(SharedColor const &color) noexcept;
2324
SharedColor colorFromComponents(ColorComponents components);
2425
ColorComponents colorComponentsFromColor(SharedColor color);
2526

0 commit comments

Comments
 (0)