Skip to content

Commit

Permalink
Property updates switching between PlatformColors would no-op (#14398)
Browse files Browse the repository at this point in the history
* Property updates switching between PlatformColors would no-op

* Change files

* format
  • Loading branch information
acoates-ms authored Mar 7, 2025
1 parent 8caf47c commit 782335b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Property updates switching between PlatformColors would no-op",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
18 changes: 8 additions & 10 deletions vnext/Microsoft.ReactNative/Fabric/AbiViewProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ winrt::Microsoft::ReactNative::Color Color::ReadValue(
switch (reader.ValueType()) {
case JSValueType::Int64: {
auto argb = reader.GetInt64();
return winrt::make<Color>(facebook::react::Color{
/*m_isDefined*/ true,
/*color*/
{static_cast<uint8_t>((argb >> 24) & 0xFF),
static_cast<uint8_t>((argb >> 16) & 0xFF),
static_cast<uint8_t>((argb >> 8) & 0xFF),
static_cast<uint8_t>(argb & 0xFF)},
{}});
return winrt::make<Color>(facebook::react::Color{/*color*/
{static_cast<uint8_t>((argb >> 24) & 0xFF),
static_cast<uint8_t>((argb >> 16) & 0xFF),
static_cast<uint8_t>((argb >> 8) & 0xFF),
static_cast<uint8_t>(argb & 0xFF)},
{}});
}
case JSValueType::Object: {
std::vector<std::string> platformColors;
Expand All @@ -96,10 +94,10 @@ winrt::Microsoft::ReactNative::Color Color::ReadValue(
SkipValue<JSValue>(reader); // Skip this property
}
}
return winrt::make<Color>(facebook::react::Color{/*m_isDefined*/ true, /*color*/ {}, std::move(platformColors)});
return winrt::make<Color>(facebook::react::Color{/*color*/ {}, std::move(platformColors)});
}
default:
return winrt::make<Color>(facebook::react::Color{/*m_isDefined*/ false, /*color*/ {0, 0, 0, 0}, {}});
return winrt::make<Color>(facebook::react::Color{/*color*/ {0, 0, 0, 0}, {}});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ namespace facebook::react {

struct Color {
bool operator==(const Color &otherColor) const {
return m_isUndefined && otherColor.m_isUndefined ||
(m_isUndefined == otherColor.m_isUndefined && m_color == otherColor.m_color &&
m_platformColor == otherColor.m_platformColor);
return m_color == otherColor.m_color && m_platformColor == otherColor.m_platformColor;
}
bool operator!=(const Color &otherColor) const {
return m_isUndefined != otherColor.m_isUndefined || m_color != otherColor.m_color ||
m_platformColor != otherColor.m_platformColor;
return m_color != otherColor.m_color || m_platformColor != otherColor.m_platformColor;
}

winrt::Windows::UI::Color AsWindowsColor() const {
Expand All @@ -36,13 +33,12 @@ struct Color {
return RGB(m_color.R, m_color.G, m_color.B) | (m_color.A << 24);
}

bool m_isUndefined;
winrt::Windows::UI::Color m_color;
std::vector<std::string> m_platformColor;
};

namespace HostPlatformColor {
static const facebook::react::Color UndefinedColor{true};
static const facebook::react::Color UndefinedColor{{0, 0, 0, 0} /*Black*/, {} /*Empty PlatformColors*/};
} // namespace HostPlatformColor

inline Color hostPlatformColorFromComponents(ColorComponents components) {
Expand All @@ -53,7 +49,6 @@ inline Color hostPlatformColorFromComponents(ColorComponents components) {
static_cast<uint8_t>((int)round(components.green * ratio) & 0xff),
static_cast<uint8_t>((int)round(components.blue * ratio) & 0xff)};
return {
/* .m_isUndefined = */ false,
/* .m_color = */ color,
/* .m_platformColor = */ {}};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ parsePlatformColor(const ContextContainer &contextContainer, int32_t surfaceId,
auto map = (std::unordered_map<std::string, std::vector<std::string>>)value;
if (map.find("windowsbrush") != map.end()) {
facebook::react::Color color = {
/* .m_isDefined = */ true,
/* .m_color = */ {},
/* .m_platformColor = */ std::move(map["windowsbrush"]),
};
Expand Down

0 comments on commit 782335b

Please sign in to comment.