Skip to content

Commit d42d463

Browse files
acoates-msfacebook-github-bot
authored andcommitted
Allow platforms to provide custom IsColorMeaningful implementation (#51478)
Summary: On windows, not all PlatformColors are convertible directly into colorComponents. For PlatformColors, the Color.isColorMeaningful may need to do something other than check the alpha component of the color. Here I'm moving the implementation of isColorMeaningful into the HostPlatformColor implemantion to allow the host platform to customize the implemenation of isColorMeaningful. ## Changelog: [INTERNAL] [ADDED] - Allow platforms to override isColorMeaningful Pull Request resolved: #51478 Test Plan: No behavior change in core. -- Will be used in react-native-windows to fix microsoft/react-native-windows#14006 Reviewed By: NickGerleman Differential Revision: D75088378 Pulled By: javache fbshipit-source-id: 0a456bfe6be93098e3d8fa22390a971e14a4312b
1 parent 6044e01 commit d42d463

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

packages/react-native/ReactCommon/react/renderer/graphics/Color.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bool isColorMeaningful(const SharedColor& color) noexcept {
1414
return false;
1515
}
1616

17-
return colorComponentsFromColor(color).alpha > 0;
17+
return hostPlatformColorIsColorMeaningful(*color);
1818
}
1919

2020
// Create Color from float RGBA values in [0, 1] range

packages/react-native/ReactCommon/react/renderer/graphics/platform/android/react/renderer/graphics/HostPlatformColor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ inline float blueFromHostPlatformColor(Color color) {
5656
return static_cast<uint8_t>((color >> 0) & 0xff);
5757
}
5858

59+
inline bool hostPlatformColorIsColorMeaningful(Color color) noexcept {
60+
return alphaFromHostPlatformColor(color) > 0;
61+
}
62+
5963
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/graphics/platform/cxx/react/renderer/graphics/HostPlatformColor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ inline float blueFromHostPlatformColor(Color color) {
4949
return static_cast<uint8_t>((color >> 0) & 0xff);
5050
}
5151

52+
inline bool hostPlatformColorIsColorMeaningful(Color color) noexcept {
53+
return alphaFromHostPlatformColor(color) > 0;
54+
}
55+
5256
inline ColorComponents colorComponentsFromHostPlatformColor(Color color) {
5357
float ratio = 255;
5458
return ColorComponents{

packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ inline float blueFromHostPlatformColor(Color color) {
104104
return color.getChannel(2) * 255;
105105
}
106106

107+
inline bool hostPlatformColorIsColorMeaningful(Color color) noexcept {
108+
return alphaFromHostPlatformColor(color) > 0;
109+
}
110+
107111
} // namespace facebook::react
108112

109113
template <>

0 commit comments

Comments
 (0)