Skip to content

Commit a30ed3d

Browse files
use ValueUnit struct
1 parent 0f27a0c commit a30ed3d

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ std::array<float, 3> getTranslateForTransformOrigin(float viewWidth, float viewH
2727

2828
for (size_t i = 0; i < transformOrigin.xy.size(); ++i) {
2929
auto& currentOrigin = transformOrigin.xy[i];
30-
if (currentOrigin.unit == YGUnitPoint) {
30+
if (currentOrigin.unit == UnitType::Point) {
3131
origin[i] = currentOrigin.value;
32-
} else if (currentOrigin.unit == YGUnitPercent) {
32+
} else if (currentOrigin.unit == UnitType::Percent) {
3333
origin[i] = ((i == 0) ? viewWidth : viewHeight) * currentOrigin.value / 100.0f;
3434
}
3535
}

packages/react-native/ReactCommon/react/renderer/components/view/conversions.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <react/renderer/core/LayoutMetrics.h>
1717
#include <react/renderer/core/PropsParserContext.h>
1818
#include <react/renderer/graphics/Transform.h>
19+
#include <react/renderer/graphics/ValueUnit.h>
1920
#include <stdlib.h>
2021
#include <yoga/YGEnums.h>
2122
#include <yoga/YGNode.h>
@@ -571,15 +572,20 @@ inline void fromRawValue(
571572
for (size_t i = 0; i < std::min(origins.size(), maxIndex); i++) {
572573
const auto& origin = origins[i];
573574
if (origin.hasType<Float>()) {
574-
transformOrigin.xy[i] = yogaStyleValueFromFloat((Float)origin);
575+
const float originFloat = (float) origin;
576+
if (std::isfinite(originFloat)) {
577+
transformOrigin.xy[i] = ValueUnit(originFloat, UnitType::Point);
578+
} else {
579+
transformOrigin.xy[i] = ValueUnit(0.0f, UnitType::Undefined);
580+
}
575581
} else if (origin.hasType<std::string>()) {
576582
const auto stringValue = (std::string)origin;
577583

578584
if (stringValue.back() == '%') {
579585
auto tryValue = folly::tryTo<float>(
580586
std::string_view(stringValue).substr(0, stringValue.length() - 1));
581587
if (tryValue.hasValue()) {
582-
transformOrigin.xy[i] = YGValue{tryValue.value(), YGUnitPercent};
588+
transformOrigin.xy[i] = ValueUnit(tryValue.value(), UnitType::Percent);
583589
}
584590
}
585591
}

packages/react-native/ReactCommon/react/renderer/graphics/Transform.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <react/renderer/graphics/RectangleEdges.h>
1717
#include <react/renderer/graphics/Size.h>
1818
#include <react/renderer/graphics/Vector.h>
19-
#include <yoga/YGValue.h>
19+
#include <react/renderer/graphics/ValueUnit.h>
2020

2121
#ifdef ANDROID
2222
#include <folly/dynamic.h>
@@ -52,18 +52,18 @@ struct TransformOperation {
5252
};
5353

5454
struct TransformOrigin {
55-
std::array<YGValue, 2> xy;
55+
std::array<ValueUnit, 2> xy;
5656
float z = 0.0f;
5757

5858
bool operator==(const TransformOrigin& other) const {
5959
return xy[0] == other.xy[0] && xy[1] == other.xy[1] && z == other.z;
6060
}
6161
bool operator!=(const TransformOrigin& other) const {
6262
return !(*this == other);
63-
};
63+
}
6464
bool isSet() const {
65-
return xy[0].value != 0.0f || xy[0].unit != YGUnitUndefined
66-
|| xy[1].value != 0.0f || xy[1].unit != YGUnitUndefined
65+
return xy[0].value != 0.0f || xy[0].unit != UnitType::Undefined
66+
|| xy[1].value != 0.0f || xy[1].unit != UnitType::Undefined
6767
|| z != 0.0f;
6868
}
6969
};

packages/react-native/ReactCommon/react/renderer/graphics/ValueUnit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct ValueUnit {
1212
float value{0.0f};
1313
UnitType unit{UnitType::Undefined};
1414

15+
ValueUnit() = default;
1516
ValueUnit(float v, UnitType u) : value(v), unit(u) {}
1617

1718
bool operator==(const ValueUnit& other) const {

0 commit comments

Comments
 (0)