Fix react/renderer ColorTest (#45485)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45485

## Changelog:

the new functions I introduced in https://github.com/facebook/react-native/pull/45365 to read color channel value, like `alphaFromColor`, will return float between 0~255 on iOS and 8bit unsigned ints on other platforms, because of different platform implementation. However that way we cannot assume consistent return value across platforms, which kind of contradicts with RN's cross platform design.

so here I make `alphaFromColor` in Color.h (the cross platform method) to always return uint8_t, while still allow `alphaFromHostPlatformColor` to return different result

[Internal] [Fixed] -

Reviewed By: christophpurrer

Differential Revision: D59826142

fbshipit-source-id: 4401918be29980474bdc8601443ae33155710f22
This commit is contained in:
Zeya Peng
2024-07-16 16:35:13 -07:00
committed by Facebook GitHub Bot
parent 50f7892a1f
commit a6f5e5adeb
2 changed files with 12 additions and 12 deletions
@@ -28,23 +28,23 @@ ColorComponents colorComponentsFromColor(SharedColor sharedColor) {
}
// Read alpha channel in [0, 255] range
float alphaFromColor(SharedColor color) {
return alphaFromHostPlatformColor(*color);
uint8_t alphaFromColor(SharedColor color) {
return static_cast<uint8_t>(std::round(alphaFromHostPlatformColor(*color)));
}
// Read red channel in [0, 255] range
float redFromColor(SharedColor color) {
return redFromHostPlatformColor(*color);
uint8_t redFromColor(SharedColor color) {
return static_cast<uint8_t>(std::round(redFromHostPlatformColor(*color)));
}
// Read green channel in [0, 255] range
float greenFromColor(SharedColor color) {
return greenFromHostPlatformColor(*color);
uint8_t greenFromColor(SharedColor color) {
return static_cast<uint8_t>(std::round(greenFromHostPlatformColor(*color)));
}
// Read blue channel in [0, 255] range
float blueFromColor(SharedColor color) {
return blueFromHostPlatformColor(*color);
uint8_t blueFromColor(SharedColor color) {
return static_cast<uint8_t>(std::round(blueFromHostPlatformColor(*color)));
}
// Create Color with RGBA values in [0, 255] range
@@ -57,10 +57,10 @@ bool isColorMeaningful(const SharedColor& color) noexcept;
SharedColor colorFromComponents(ColorComponents components);
ColorComponents colorComponentsFromColor(SharedColor color);
float alphaFromColor(SharedColor color);
float redFromColor(SharedColor color);
float greenFromColor(SharedColor color);
float blueFromColor(SharedColor color);
uint8_t alphaFromColor(SharedColor color);
uint8_t redFromColor(SharedColor color);
uint8_t greenFromColor(SharedColor color);
uint8_t blueFromColor(SharedColor color);
SharedColor colorFromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SharedColor clearColor();