Compare commits

...
1 Commits
Author SHA1 Message Date
CodemodService Bot aea52d3cd0 Fix CQS signal modernize-use-designated-initializers in xplat/js/react-native-github/packages [A]
Reviewed By: rshest

Differential Revision: D83395511
2025-09-29 01:34:42 -07:00
12 changed files with 140 additions and 102 deletions
@@ -55,10 +55,12 @@ struct CSSDataTypeParser<CSSRatio> {
if (std::holds_alternative<CSSNumber>(denominator) &&
std::get<CSSNumber>(denominator).value >= 0) {
parseNextCSSValue<CSSNumber>(parser, CSSDelimiter::Solidus);
return CSSRatio{numeratorValue, std::get<CSSNumber>(denominator).value};
return CSSRatio{
.numerator = numeratorValue,
.denominator = std::get<CSSNumber>(denominator).value};
}
return CSSRatio{numeratorValue, 1.0f};
return CSSRatio{.numerator = numeratorValue, .denominator = 1.0f};
}
return {};
@@ -310,7 +310,7 @@ struct CSSDataTypeParser<CSSScale> {
? std::get<CSSNumber>(y).value
: std::get<CSSPercentage>(y).value / 100.0f;
return CSSScale{normX, normY};
return CSSScale{.x = normX, .y = normY};
}
};
@@ -177,7 +177,7 @@ TEST(CSSFilter, drop_shadow_no_blur_pre_color) {
std::get<CSSDropShadowFilter>(value).standardDeviation.unit,
CSSLengthUnit::Px);
CSSColor red{255, 0, 0, 255};
CSSColor red{.r = 255, .g = 0, .b = 0, .a = 255};
EXPECT_EQ(std::get<CSSDropShadowFilter>(value).color, red);
}
@@ -195,7 +195,7 @@ TEST(CSSFilter, drop_shadow_no_blur_post_color) {
EXPECT_EQ(
std::get<CSSDropShadowFilter>(value).standardDeviation.unit,
CSSLengthUnit::Px);
CSSColor red{255, 0, 0, 255};
CSSColor red{.r = 255, .g = 0, .b = 0, .a = 255};
EXPECT_EQ(std::get<CSSDropShadowFilter>(value).color, red);
}
@@ -231,7 +231,7 @@ TEST(CSSFilter, drop_shadow_with_blur_pre_color) {
std::get<CSSDropShadowFilter>(value).standardDeviation.unit,
CSSLengthUnit::Px);
CSSColor red{255, 0, 0, 255};
CSSColor red{.r = 255, .g = 0, .b = 0, .a = 255};
EXPECT_EQ(std::get<CSSDropShadowFilter>(value).color, red);
}
@@ -250,7 +250,7 @@ TEST(CSSFilter, drop_shadow_with_blur_post_color) {
std::get<CSSDropShadowFilter>(value).standardDeviation.unit,
CSSLengthUnit::Px);
CSSColor red{255, 0, 0, 255};
CSSColor red{.r = 255, .g = 0, .b = 0, .a = 255};
EXPECT_EQ(std::get<CSSDropShadowFilter>(value).color, red);
}
@@ -550,7 +550,7 @@ TEST(CSSFilter, filter_list) {
EXPECT_EQ(
std::get<CSSDropShadowFilter>(list[2]).standardDeviation.unit,
CSSLengthUnit::Px);
CSSColor red{255, 0, 0, 255};
CSSColor red{.r = 255, .g = 0, .b = 0, .a = 255};
EXPECT_EQ(std::get<CSSDropShadowFilter>(list[2]).color, red);
EXPECT_TRUE(std::holds_alternative<CSSDropShadowFilter>(list[3]));
@@ -94,7 +94,7 @@ TEST(CSSShadow, trailing_color) {
EXPECT_EQ(shadow.spreadDistance.value, 0.0f);
EXPECT_EQ(shadow.spreadDistance.unit, CSSLengthUnit::Px);
CSSColor red{255u, 0u, 0u, 255u};
CSSColor red{.r = 255u, .g = 0u, .b = 0u, .a = 255u};
EXPECT_EQ(shadow.color, red);
EXPECT_FALSE(shadow.inset);
}
@@ -113,7 +113,7 @@ TEST(CSSShadow, leading_color) {
EXPECT_EQ(shadow.spreadDistance.value, 0.0f);
EXPECT_EQ(shadow.spreadDistance.unit, CSSLengthUnit::Px);
CSSColor red{255u, 0u, 0u, 255u};
CSSColor red{.r = 255u, .g = 0u, .b = 0u, .a = 255u};
EXPECT_EQ(shadow.color, red);
EXPECT_FALSE(shadow.inset);
}
@@ -132,7 +132,7 @@ TEST(CSSShadow, color_function) {
EXPECT_EQ(shadow.spreadDistance.value, 0.0f);
EXPECT_EQ(shadow.spreadDistance.unit, CSSLengthUnit::Px);
CSSColor red{255u, 0u, 0u, 128u};
CSSColor red{.r = 255u, .g = 0u, .b = 0u, .a = 128u};
EXPECT_EQ(shadow.color, red);
EXPECT_FALSE(shadow.inset);
}
@@ -202,7 +202,7 @@ TEST(CSShadow, color_length_inset) {
EXPECT_EQ(shadow.spreadDistance.value, 0.0f);
EXPECT_EQ(shadow.spreadDistance.unit, CSSLengthUnit::Px);
CSSColor red{255u, 0u, 0u, 255u};
CSSColor red{.r = 255u, .g = 0u, .b = 0u, .a = 255u};
EXPECT_EQ(shadow.color, red);
EXPECT_TRUE(shadow.inset);
}
@@ -224,7 +224,7 @@ TEST(CSSShadow, multiple_shadows) {
EXPECT_EQ(shadows[0].spreadDistance.value, 0.0f);
EXPECT_EQ(shadows[0].spreadDistance.unit, CSSLengthUnit::Px);
CSSColor red{255u, 0u, 0u, 255u};
CSSColor red{.r = 255u, .g = 0u, .b = 0u, .a = 255u};
EXPECT_EQ(shadows[0].color, red);
EXPECT_FALSE(shadows[0].inset);
@@ -268,7 +268,7 @@ TEST(CSSShadow, multiple_shadows_with_new_line) {
EXPECT_EQ(shadows[0].spreadDistance.value, 0.0f);
EXPECT_EQ(shadows[0].spreadDistance.unit, CSSLengthUnit::Px);
CSSColor red{255u, 0u, 0u, 255u};
CSSColor red{.r = 255u, .g = 0u, .b = 0u, .a = 255u};
EXPECT_EQ(shadows[0].color, red);
EXPECT_FALSE(shadows[0].inset);
@@ -151,7 +151,9 @@ Rect getScrollableContentBounds(
: std::max(
paddingFrame.getMaxX(), contentBounds.getMaxX() + paddingRight);
return Rect{Point{minX, minY}, Size{maxX - minX, maxY - minY}};
return Rect{
.origin = Point{.x = minX, .y = minY},
.size = Size{.width = maxX - minX, .height = maxY - minY}};
}
} // namespace
@@ -27,17 +27,19 @@ std::shared_ptr<ShadowNode> ComponentBuilder::build(
}
auto family = componentDescriptor.createFamily(ShadowNodeFamilyFragment{
elementFragment.tag, elementFragment.surfaceId, nullptr});
.tag = elementFragment.tag,
.surfaceId = elementFragment.surfaceId,
.instanceHandle = nullptr});
auto initialState =
componentDescriptor.createInitialState(elementFragment.props, family);
auto constShadowNode = componentDescriptor.createShadowNode(
ShadowNodeFragment{
elementFragment.props,
std::make_shared<
.props = elementFragment.props,
.children = std::make_shared<
const std::vector<std::shared_ptr<const ShadowNode>>>(children),
initialState},
.state = initialState},
family);
if (elementFragment.stateCallback) {
@@ -46,9 +48,9 @@ std::shared_ptr<ShadowNode> ComponentBuilder::build(
constShadowNode = componentDescriptor.cloneShadowNode(
*constShadowNode,
ShadowNodeFragment{
ShadowNodeFragment::propsPlaceholder(),
ShadowNodeFragment::childrenPlaceholder(),
newState});
.props = ShadowNodeFragment::propsPlaceholder(),
.children = ShadowNodeFragment::childrenPlaceholder(),
.state = newState});
}
auto shadowNode = std::const_pointer_cast<ShadowNode>(constShadowNode);
@@ -26,7 +26,9 @@ inline ComponentBuilder simpleComponentBuilder(
auto componentDescriptorRegistry =
componentDescriptorProviderRegistry.createComponentDescriptorRegistry(
ComponentDescriptorParameters{
eventDispatcher, std::move(contextContainer), nullptr});
.eventDispatcher = eventDispatcher,
.contextContainer = std::move(contextContainer),
.flavor = nullptr});
componentDescriptorProviderRegistry.add(
concreteComponentDescriptorProvider<RootComponentDescriptor>());
@@ -53,17 +53,20 @@ SharedColor colorFromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
}
SharedColor clearColor() {
static SharedColor color = colorFromComponents(ColorComponents{0, 0, 0, 0});
static SharedColor color = colorFromComponents(
ColorComponents{.red = 0, .green = 0, .blue = 0, .alpha = 0});
return color;
}
SharedColor blackColor() {
static SharedColor color = colorFromComponents(ColorComponents{0, 0, 0, 1});
static SharedColor color = colorFromComponents(
ColorComponents{.red = 0, .green = 0, .blue = 0, .alpha = 1});
return color;
}
SharedColor whiteColor() {
static SharedColor color = colorFromComponents(ColorComponents{1, 1, 1, 1});
static SharedColor color = colorFromComponents(
ColorComponents{.red = 1, .green = 1, .blue = 1, .alpha = 1});
return color;
}
@@ -21,8 +21,8 @@ namespace facebook::react {
* Contains the location and dimensions of a rectangle.
*/
struct Rect {
Point origin{0, 0};
Size size{0, 0};
Point origin{.x = 0, .y = 0};
Size size{.width = 0, .height = 0};
bool operator==(const Rect& rhs) const noexcept {
return std::tie(this->origin, this->size) == std::tie(rhs.origin, rhs.size);
@@ -51,7 +51,7 @@ struct Rect {
return origin.y + size.height / 2;
}
Point getCenter() const noexcept {
return {getMidX(), getMidY()};
return {.x = getMidX(), .y = getMidY()};
}
void unionInPlace(const Rect& rect) noexcept {
@@ -59,8 +59,8 @@ struct Rect {
auto y1 = std::min(getMinY(), rect.getMinY());
auto x2 = std::max(getMaxX(), rect.getMaxX());
auto y2 = std::max(getMaxY(), rect.getMaxY());
origin = {x1, y1};
size = {x2 - x1, y2 - y1};
origin = {.x = x1, .y = y1};
size = {.width = x2 - x1, .height = y2 - y1};
}
bool containsPoint(Point point) noexcept {
@@ -84,7 +84,9 @@ struct Rect {
return {};
}
return {{x1, y1}, {intersectionWidth, intersectionHeight}};
return {
.origin = {.x = x1, .y = y1},
.size = {.width = intersectionWidth, .height = intersectionHeight}};
}
static Rect boundingRect(
@@ -112,9 +114,10 @@ struct Rect {
rightBottomPoint.y = std::max(rightBottomPoint.y, d.y);
return {
leftTopPoint,
{rightBottomPoint.x - leftTopPoint.x,
rightBottomPoint.y - leftTopPoint.y}};
.origin = leftTopPoint,
.size = {
.width = rightBottomPoint.x - leftTopPoint.x,
.height = rightBottomPoint.y - leftTopPoint.y}};
}
};
@@ -77,9 +77,11 @@ using EdgeInsets = RectangleEdges<Float>;
*/
inline Rect insetBy(const Rect& rect, const EdgeInsets& insets) noexcept {
return Rect{
{rect.origin.x + insets.left, rect.origin.y + insets.top},
{rect.size.width - insets.left - insets.right,
rect.size.height - insets.top - insets.bottom}};
.origin =
{.x = rect.origin.x + insets.left, .y = rect.origin.y + insets.top},
.size = {
.width = rect.size.width - insets.left - insets.right,
.height = rect.size.height - insets.top - insets.bottom}};
}
/*
@@ -87,9 +89,11 @@ inline Rect insetBy(const Rect& rect, const EdgeInsets& insets) noexcept {
*/
inline Rect outsetBy(const Rect& rect, const EdgeInsets& outsets) noexcept {
return Rect{
{rect.origin.x - outsets.left, rect.origin.y - outsets.top},
{rect.size.width + outsets.left + outsets.right,
rect.size.height + outsets.top + outsets.bottom}};
.origin =
{.x = rect.origin.x - outsets.left, .y = rect.origin.y - outsets.top},
.size = {
.width = rect.size.width + outsets.left + outsets.right,
.height = rect.size.height + outsets.top + outsets.bottom}};
}
} // namespace facebook::react
@@ -31,10 +31,10 @@ namespace facebook::react {
auto transform = Transform{};
auto Zero = ValueUnit(0, UnitType::Point);
transform.operations.push_back(TransformOperation{
TransformOperationType::Perspective,
ValueUnit(perspective, UnitType::Point),
Zero,
Zero});
.type = TransformOperationType::Perspective,
.x = ValueUnit(perspective, UnitType::Point),
.y = Zero,
.z = Zero});
transform.matrix[11] = -1 / perspective;
return transform;
}
@@ -46,10 +46,10 @@ namespace facebook::react {
Float zprime = isZero(z) ? 0 : z;
if (xprime != 1 || yprime != 1 || zprime != 1) {
transform.operations.push_back(TransformOperation{
TransformOperationType::Scale,
ValueUnit(xprime, UnitType::Point),
ValueUnit(yprime, UnitType::Point),
ValueUnit(zprime, UnitType::Point)});
.type = TransformOperationType::Scale,
.x = ValueUnit(xprime, UnitType::Point),
.y = ValueUnit(yprime, UnitType::Point),
.z = ValueUnit(zprime, UnitType::Point)});
transform.matrix[0] = xprime;
transform.matrix[5] = yprime;
transform.matrix[10] = zprime;
@@ -65,10 +65,10 @@ Transform::Translate(Float x, Float y, Float z) noexcept {
Float zprime = isZero(z) ? 0 : z;
if (xprime != 0 || yprime != 0 || zprime != 0) {
transform.operations.push_back(TransformOperation{
TransformOperationType::Translate,
ValueUnit(xprime, UnitType::Point),
ValueUnit(yprime, UnitType::Point),
ValueUnit(zprime, UnitType::Point)});
.type = TransformOperationType::Translate,
.x = ValueUnit(xprime, UnitType::Point),
.y = ValueUnit(yprime, UnitType::Point),
.z = ValueUnit(zprime, UnitType::Point)});
transform.matrix[12] = xprime;
transform.matrix[13] = yprime;
transform.matrix[14] = zprime;
@@ -81,10 +81,10 @@ Transform::Translate(Float x, Float y, Float z) noexcept {
Float xprime = isZero(x) ? 0 : x;
Float yprime = isZero(y) ? 0 : y;
transform.operations.push_back(TransformOperation{
TransformOperationType::Skew,
ValueUnit(xprime, UnitType::Point),
ValueUnit(yprime, UnitType::Point),
ValueUnit(0, UnitType::Point)});
.type = TransformOperationType::Skew,
.x = ValueUnit(xprime, UnitType::Point),
.y = ValueUnit(yprime, UnitType::Point),
.z = ValueUnit(0, UnitType::Point)});
transform.matrix[4] = std::tan(xprime);
transform.matrix[1] = std::tan(yprime);
return transform;
@@ -95,10 +95,10 @@ Transform::Translate(Float x, Float y, Float z) noexcept {
if (!isZero(radians)) {
auto Zero = ValueUnit(0, UnitType::Point);
transform.operations.push_back(TransformOperation{
TransformOperationType::Rotate,
ValueUnit(radians, UnitType::Point),
Zero,
Zero});
.type = TransformOperationType::Rotate,
.x = ValueUnit(radians, UnitType::Point),
.y = Zero,
.z = Zero});
transform.matrix[5] = std::cos(radians);
transform.matrix[6] = std::sin(radians);
transform.matrix[9] = -std::sin(radians);
@@ -112,10 +112,10 @@ Transform::Translate(Float x, Float y, Float z) noexcept {
if (!isZero(radians)) {
auto Zero = ValueUnit(0, UnitType::Point);
transform.operations.push_back(TransformOperation{
TransformOperationType::Rotate,
Zero,
ValueUnit(radians, UnitType::Point),
Zero});
.type = TransformOperationType::Rotate,
.x = Zero,
.y = ValueUnit(radians, UnitType::Point),
.z = Zero});
transform.matrix[0] = std::cos(radians);
transform.matrix[2] = -std::sin(radians);
transform.matrix[8] = std::sin(radians);
@@ -129,10 +129,10 @@ Transform::Translate(Float x, Float y, Float z) noexcept {
if (!isZero(radians)) {
auto Zero = ValueUnit(0, UnitType::Point);
transform.operations.push_back(TransformOperation{
TransformOperationType::Rotate,
Zero,
Zero,
ValueUnit(radians, UnitType::Point)});
.type = TransformOperationType::Rotate,
.x = Zero,
.y = Zero,
.z = ValueUnit(radians, UnitType::Point)});
transform.matrix[0] = std::cos(radians);
transform.matrix[1] = std::sin(radians);
transform.matrix[4] = -std::sin(radians);
@@ -205,24 +205,44 @@ Transform::Translate(Float x, Float y, Float z) noexcept {
switch (type) {
case TransformOperationType::Arbitrary:
return TransformOperation{
TransformOperationType::Arbitrary, Zero, Zero, Zero};
.type = TransformOperationType::Arbitrary,
.x = Zero,
.y = Zero,
.z = Zero};
case TransformOperationType::Perspective:
return TransformOperation{
TransformOperationType::Perspective, Zero, Zero, Zero};
.type = TransformOperationType::Perspective,
.x = Zero,
.y = Zero,
.z = Zero};
case TransformOperationType::Scale:
return TransformOperation{TransformOperationType::Scale, One, One, One};
return TransformOperation{
.type = TransformOperationType::Scale, .x = One, .y = One, .z = One};
case TransformOperationType::Translate:
return TransformOperation{
TransformOperationType::Translate, Zero, Zero, Zero};
.type = TransformOperationType::Translate,
.x = Zero,
.y = Zero,
.z = Zero};
case TransformOperationType::Rotate:
return TransformOperation{
TransformOperationType::Rotate, Zero, Zero, Zero};
.type = TransformOperationType::Rotate,
.x = Zero,
.y = Zero,
.z = Zero};
case TransformOperationType::Skew:
return TransformOperation{TransformOperationType::Skew, Zero, Zero, Zero};
return TransformOperation{
.type = TransformOperationType::Skew,
.x = Zero,
.y = Zero,
.z = Zero};
default:
case TransformOperationType::Identity:
return TransformOperation{
TransformOperationType::Identity, Zero, Zero, Zero};
.type = TransformOperationType::Identity,
.x = Zero,
.y = Zero,
.z = Zero};
}
}
@@ -278,20 +298,20 @@ Transform::Translate(Float x, Float y, Float z) noexcept {
result = result *
Transform::FromTransformOperation(
TransformOperation{
type,
ValueUnit(
.type = type,
.x = ValueUnit(
lhsOp.x.resolve(size.width) +
(rhsOp.x.resolve(size.width) -
lhsOp.x.resolve(size.width)) *
animationProgress,
UnitType::Point),
ValueUnit(
.y = ValueUnit(
lhsOp.y.resolve(size.height) +
(rhsOp.y.resolve(size.height) -
lhsOp.y.resolve(size.height)) *
animationProgress,
UnitType::Point),
ValueUnit(
.z = ValueUnit(
lhsOp.z.resolve(0) +
(rhsOp.z.resolve(0) - lhsOp.z.resolve(0)) *
animationProgress,
@@ -424,9 +444,9 @@ Point operator*(const Point& point, const Transform& transform) {
return point;
}
auto result = transform * Vector{point.x, point.y, 0, 1};
auto result = transform * Vector{.x = point.x, .y = point.y, .z = 0, .w = 1};
return {result.x, result.y};
return {.x = result.x, .y = result.y};
}
Rect operator*(const Rect& rect, const Transform& transform) {
@@ -435,20 +455,20 @@ Rect operator*(const Rect& rect, const Transform& transform) {
}
Rect Transform::applyWithCenter(const Rect& rect, const Point& center) const {
auto a = Point{rect.origin.x, rect.origin.y} - center;
auto b = Point{rect.getMaxX(), rect.origin.y} - center;
auto c = Point{rect.getMaxX(), rect.getMaxY()} - center;
auto d = Point{rect.origin.x, rect.getMaxY()} - center;
auto a = Point{.x = rect.origin.x, .y = rect.origin.y} - center;
auto b = Point{.x = rect.getMaxX(), .y = rect.origin.y} - center;
auto c = Point{.x = rect.getMaxX(), .y = rect.getMaxY()} - center;
auto d = Point{.x = rect.origin.x, .y = rect.getMaxY()} - center;
auto vectorA = *this * Vector{a.x, a.y, 0, 1};
auto vectorB = *this * Vector{b.x, b.y, 0, 1};
auto vectorC = *this * Vector{c.x, c.y, 0, 1};
auto vectorD = *this * Vector{d.x, d.y, 0, 1};
auto vectorA = *this * Vector{.x = a.x, .y = a.y, .z = 0, .w = 1};
auto vectorB = *this * Vector{.x = b.x, .y = b.y, .z = 0, .w = 1};
auto vectorC = *this * Vector{.x = c.x, .y = c.y, .z = 0, .w = 1};
auto vectorD = *this * Vector{.x = d.x, .y = d.y, .z = 0, .w = 1};
Point transformedA{vectorA.x + center.x, vectorA.y + center.y};
Point transformedB{vectorB.x + center.x, vectorB.y + center.y};
Point transformedC{vectorC.x + center.x, vectorC.y + center.y};
Point transformedD{vectorD.x + center.x, vectorD.y + center.y};
Point transformedA{.x = vectorA.x + center.x, .y = vectorA.y + center.y};
Point transformedB{.x = vectorB.x + center.x, .y = vectorB.y + center.y};
Point transformedC{.x = vectorC.x + center.x, .y = vectorC.y + center.y};
Point transformedD{.x = vectorD.x + center.x, .y = vectorD.y + center.y};
return Rect::boundingRect(
transformedA, transformedB, transformedC, transformedD);
@@ -464,13 +484,13 @@ EdgeInsets operator*(const EdgeInsets& edgeInsets, const Transform& transform) {
Vector operator*(const Transform& transform, const Vector& vector) {
return {
vector.x * transform.at(0, 0) + vector.y * transform.at(1, 0) +
.x = vector.x * transform.at(0, 0) + vector.y * transform.at(1, 0) +
vector.z * transform.at(2, 0) + vector.w * transform.at(3, 0),
vector.x * transform.at(0, 1) + vector.y * transform.at(1, 1) +
.y = vector.x * transform.at(0, 1) + vector.y * transform.at(1, 1) +
vector.z * transform.at(2, 1) + vector.w * transform.at(3, 1),
vector.x * transform.at(0, 2) + vector.y * transform.at(1, 2) +
.z = vector.x * transform.at(0, 2) + vector.y * transform.at(1, 2) +
vector.z * transform.at(2, 2) + vector.w * transform.at(3, 2),
vector.x * transform.at(0, 3) + vector.y * transform.at(1, 3) +
.w = vector.x * transform.at(0, 3) + vector.y * transform.at(1, 3) +
vector.z * transform.at(2, 3) + vector.w * transform.at(3, 3),
};
}
@@ -56,10 +56,10 @@ inline bool hostPlatformColorIsColorMeaningful(Color color) noexcept {
inline ColorComponents colorComponentsFromHostPlatformColor(Color color) {
float ratio = 255;
return ColorComponents{
static_cast<float>(redFromHostPlatformColor(color)) / ratio,
static_cast<float>(greenFromHostPlatformColor(color)) / ratio,
static_cast<float>(blueFromHostPlatformColor(color)) / ratio,
static_cast<float>(alphaFromHostPlatformColor(color)) / ratio};
.red = static_cast<float>(redFromHostPlatformColor(color)) / ratio,
.green = static_cast<float>(greenFromHostPlatformColor(color)) / ratio,
.blue = static_cast<float>(blueFromHostPlatformColor(color)) / ratio,
.alpha = static_cast<float>(alphaFromHostPlatformColor(color)) / ratio};
}
} // namespace facebook::react