mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
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: https://github.com/facebook/react-native/pull/51478 Test Plan: No behavior change in core. -- Will be used in react-native-windows to fix https://github.com/microsoft/react-native-windows/issues/14006 Reviewed By: NickGerleman Differential Revision: D75088378 Pulled By: javache fbshipit-source-id: 0a456bfe6be93098e3d8fa22390a971e14a4312b
This commit is contained in:
1 parent
6044e01460
commit
d42d46306a
4 files changed
+13
-1
No files matched your search
@@ -14,7 +14,7 @@ bool isColorMeaningful(const SharedColor& color) noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
return colorComponentsFromColor(color).alpha > 0;
|
||||
return hostPlatformColorIsColorMeaningful(*color);
|
||||
}
|
||||
|
||||
// Create Color from float RGBA values in [0, 1] range
|
||||
|
||||
+4
@@ -56,4 +56,8 @@ inline float blueFromHostPlatformColor(Color color) {
|
||||
return static_cast<uint8_t>((color >> 0) & 0xff);
|
||||
}
|
||||
|
||||
inline bool hostPlatformColorIsColorMeaningful(Color color) noexcept {
|
||||
return alphaFromHostPlatformColor(color) > 0;
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
+4
@@ -49,6 +49,10 @@ inline float blueFromHostPlatformColor(Color color) {
|
||||
return static_cast<uint8_t>((color >> 0) & 0xff);
|
||||
}
|
||||
|
||||
inline bool hostPlatformColorIsColorMeaningful(Color color) noexcept {
|
||||
return alphaFromHostPlatformColor(color) > 0;
|
||||
}
|
||||
|
||||
inline ColorComponents colorComponentsFromHostPlatformColor(Color color) {
|
||||
float ratio = 255;
|
||||
return ColorComponents{
|
||||
|
||||
+4
@@ -104,6 +104,10 @@ inline float blueFromHostPlatformColor(Color color) {
|
||||
return color.getChannel(2) * 255;
|
||||
}
|
||||
|
||||
inline bool hostPlatformColorIsColorMeaningful(Color color) noexcept {
|
||||
return alphaFromHostPlatformColor(color) > 0;
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
template <>
|
||||
|
||||
Reference in new issue
Block a user