mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use uint32_t as internal Color representation (#53507)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53507 We need this to be an unsigned value everywhere but all the API's and interfaces described this a signed number. While this doesn't make a difference in practice, it's better to explicit. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D81230050 fbshipit-source-id: 1eb914a79b9b94654cfa54c20a81ce689f79dcb9
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5858c8309d
commit
a44c5a0dbf
+1
-1
@@ -310,7 +310,7 @@ static void updateBorderColorPropValue(
|
||||
const std::optional<SharedColor>& newColor,
|
||||
const std::optional<SharedColor>& oldColor) {
|
||||
if (newColor != oldColor) {
|
||||
result[propName] = newColor.has_value() ? *newColor.value() : NULL;
|
||||
result[propName] = *newColor.value_or(SharedColor());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
using Color = int32_t;
|
||||
using Color = uint32_t;
|
||||
|
||||
namespace HostPlatformColor {
|
||||
constexpr facebook::react::Color UndefinedColor = 0;
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ inline SharedColor parsePlatformColor(
|
||||
auto color =
|
||||
getColorFromJava(fabricUIManager, surfaceId, *javaResourcePaths);
|
||||
|
||||
auto argb = (int64_t)color;
|
||||
auto argb = (uint32_t)color;
|
||||
auto ratio = 255.f;
|
||||
colorComponents.alpha = ((argb >> 24) & 0xFF) / ratio;
|
||||
colorComponents.red = ((argb >> 16) & 0xFF) / ratio;
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
using Color = int32_t;
|
||||
using Color = uint32_t;
|
||||
|
||||
namespace HostPlatformColor {
|
||||
constexpr facebook::react::Color UndefinedColor = 0;
|
||||
|
||||
+8
-8
@@ -14,18 +14,18 @@
|
||||
namespace facebook::react {
|
||||
|
||||
struct DynamicColor {
|
||||
int32_t lightColor = 0;
|
||||
int32_t darkColor = 0;
|
||||
int32_t highContrastLightColor = 0;
|
||||
int32_t highContrastDarkColor = 0;
|
||||
uint32_t lightColor = 0;
|
||||
uint32_t darkColor = 0;
|
||||
uint32_t highContrastLightColor = 0;
|
||||
uint32_t highContrastDarkColor = 0;
|
||||
};
|
||||
|
||||
struct Color {
|
||||
Color(int32_t color);
|
||||
Color(uint32_t color);
|
||||
Color(const DynamicColor& dynamicColor);
|
||||
Color(const ColorComponents& components);
|
||||
Color() : uiColor_(nullptr){};
|
||||
int32_t getColor() const;
|
||||
uint32_t getColor() const;
|
||||
std::size_t getUIColorHash() const;
|
||||
|
||||
static Color createSemanticColor(std::vector<std::string>& semanticItems);
|
||||
@@ -38,7 +38,7 @@ struct Color {
|
||||
|
||||
ColorComponents getColorComponents() const {
|
||||
float ratio = 255;
|
||||
int32_t primitiveColor = getColor();
|
||||
uint32_t primitiveColor = getColor();
|
||||
return ColorComponents{
|
||||
.red = (float)((primitiveColor >> 16) & 0xff) / ratio,
|
||||
.green = (float)((primitiveColor >> 8) & 0xff) / ratio,
|
||||
@@ -47,7 +47,7 @@ struct Color {
|
||||
}
|
||||
bool operator==(const Color& other) const;
|
||||
bool operator!=(const Color& other) const;
|
||||
operator int32_t() const {
|
||||
operator uint32_t() const {
|
||||
return getColor();
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -36,7 +36,7 @@ bool UIColorIsP3ColorSpace(const std::shared_ptr<void> &uiColor)
|
||||
return false;
|
||||
}
|
||||
|
||||
UIColor *_Nullable UIColorFromInt32(int32_t intColor)
|
||||
UIColor *_Nullable UIColorFromInt32(uint32_t intColor)
|
||||
{
|
||||
CGFloat a = CGFloat((intColor >> 24) & 0xFF) / 255.0;
|
||||
CGFloat r = CGFloat((intColor >> 16) & 0xFF) / 255.0;
|
||||
@@ -49,10 +49,10 @@ UIColor *_Nullable UIColorFromInt32(int32_t intColor)
|
||||
|
||||
UIColor *_Nullable UIColorFromDynamicColor(const facebook::react::DynamicColor &dynamicColor)
|
||||
{
|
||||
int32_t light = dynamicColor.lightColor;
|
||||
int32_t dark = dynamicColor.darkColor;
|
||||
int32_t highContrastLight = dynamicColor.highContrastLightColor;
|
||||
int32_t highContrastDark = dynamicColor.highContrastDarkColor;
|
||||
uint32_t light = dynamicColor.lightColor;
|
||||
uint32_t dark = dynamicColor.darkColor;
|
||||
uint32_t highContrastLight = dynamicColor.highContrastLightColor;
|
||||
uint32_t highContrastDark = dynamicColor.highContrastDarkColor;
|
||||
|
||||
UIColor *lightColor = UIColorFromInt32(light);
|
||||
UIColor *darkColor = UIColorFromInt32(dark);
|
||||
@@ -83,7 +83,7 @@ UIColor *_Nullable UIColorFromDynamicColor(const facebook::react::DynamicColor &
|
||||
return nil;
|
||||
}
|
||||
|
||||
int32_t ColorFromColorComponents(const facebook::react::ColorComponents &components)
|
||||
uint32_t ColorFromColorComponents(const facebook::react::ColorComponents &components)
|
||||
{
|
||||
float ratio = 255;
|
||||
auto color = ((int32_t)round((float)components.alpha * ratio) & 0xff) << 24 |
|
||||
@@ -92,7 +92,7 @@ int32_t ColorFromColorComponents(const facebook::react::ColorComponents &compone
|
||||
return color;
|
||||
}
|
||||
|
||||
int32_t ColorFromUIColor(UIColor *color)
|
||||
uint32_t ColorFromUIColor(UIColor *color)
|
||||
{
|
||||
CGFloat rgba[4];
|
||||
[color getRed:&rgba[0] green:&rgba[1] blue:&rgba[2] alpha:&rgba[3]];
|
||||
@@ -100,7 +100,7 @@ int32_t ColorFromUIColor(UIColor *color)
|
||||
{.red = (float)rgba[0], .green = (float)rgba[1], .blue = (float)rgba[2], .alpha = (float)rgba[3]});
|
||||
}
|
||||
|
||||
int32_t ColorFromUIColorForSpecificTraitCollection(
|
||||
uint32_t ColorFromUIColorForSpecificTraitCollection(
|
||||
const std::shared_ptr<void> &uiColor,
|
||||
UITraitCollection *traitCollection)
|
||||
{
|
||||
@@ -113,7 +113,7 @@ int32_t ColorFromUIColorForSpecificTraitCollection(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t ColorFromUIColor(const std::shared_ptr<void> &uiColor)
|
||||
uint32_t ColorFromUIColor(const std::shared_ptr<void> &uiColor)
|
||||
{
|
||||
return ColorFromUIColorForSpecificTraitCollection(uiColor, [UITraitCollection currentTraitCollection]);
|
||||
}
|
||||
@@ -172,7 +172,7 @@ std::size_t hashFromUIColor(const std::shared_ptr<void> &uiColor)
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
Color::Color(int32_t color)
|
||||
Color::Color(uint32_t color)
|
||||
{
|
||||
uiColor_ = wrapManagedObject(UIColorFromInt32(color));
|
||||
uiColorHashValue_ = facebook::react::hash_combine(color, 0);
|
||||
@@ -217,7 +217,7 @@ bool Color::operator!=(const Color &other) const
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
int32_t Color::getColor() const
|
||||
uint32_t Color::getColor() const
|
||||
{
|
||||
return ColorFromUIColor(uiColor_);
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
const int32_t DEFAULT_TEXT_COLOR = 0xFFFFFFFF;
|
||||
const int32_t DEFAULT_BACKGROUND_COLOR = 0xFF2584E8;
|
||||
const uint32_t DEFAULT_TEXT_COLOR = 0xFFFFFFFF;
|
||||
const uint32_t DEFAULT_BACKGROUND_COLOR = 0xFF2584E8;
|
||||
|
||||
DevLoadingViewModule::DevLoadingViewModule(
|
||||
std::shared_ptr<CallInvoker> jsInvoker,
|
||||
@@ -27,8 +27,8 @@ DevLoadingViewModule::~DevLoadingViewModule() {
|
||||
void DevLoadingViewModule::showMessage(
|
||||
jsi::Runtime& /*rt*/,
|
||||
const std::string& message,
|
||||
std::optional<int32_t> textColor,
|
||||
std::optional<int32_t> backgroundColor) {
|
||||
std::optional<uint32_t> textColor,
|
||||
std::optional<uint32_t> backgroundColor) {
|
||||
if (auto devUIDelegate = devUIDelegate_.lock()) {
|
||||
devUIDelegate->showLoadingView(
|
||||
message,
|
||||
|
||||
@@ -27,8 +27,8 @@ class DevLoadingViewModule
|
||||
void showMessage(
|
||||
jsi::Runtime& rt,
|
||||
const std::string& message,
|
||||
std::optional<int32_t> textColor,
|
||||
std::optional<int32_t> backgroundColor);
|
||||
std::optional<uint32_t> textColor,
|
||||
std::optional<uint32_t> backgroundColor);
|
||||
|
||||
void hide(jsi::Runtime& rt);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user