Measure with transform bugfix (#44821)

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

Changelog: [Internal]

- Originally D37994809 was attempted to fix `Inverted FlatList` but was put behind Feature Toggle because it was causing problems in other scenarios.
- Later, D45866231 which was trying to fix scaling transform issue helped solve the issue attempted by the original diff.
- But after that points, Unit test around `computeRelativeLayoutMetrics` was having two variants where Feature Toggle for D37994809 was checked in with a wrong expected value.
- This diff revert D37994809 changes and clean up the unit test.

Reviewed By: NickGerleman

Differential Revision: D58197918

fbshipit-source-id: d8ae552018617e785e4010bc5805c53a875e02a3
This commit is contained in:
Soe Lynn
2024-06-10 21:03:45 -07:00
committed by Facebook GitHub Bot
parent 712ff8cdba
commit 0d345698d8
5 changed files with 157 additions and 186 deletions
@@ -1953,7 +1953,6 @@ public class com/facebook/react/common/network/OkHttpCallUtil {
}
public class com/facebook/react/config/ReactFeatureFlags {
public static field calculateTransformedFramesEnabled Z
public static field dispatchPointerEvents Z
public static field enableBridgelessArchitecture Z
public static field enableCppPropsIteratorSetter Z
@@ -72,9 +72,6 @@ public class ReactFeatureFlags {
/** Feature flag to configure eager attachment of the root view/initialisation of the JS code */
public static boolean enableEagerRootViewAttachment = false;
/** Enables or disables calculation of Transformed Frames */
public static boolean calculateTransformedFramesEnabled = false;
public static boolean dispatchPointerEvents = false;
/**
@@ -396,10 +396,6 @@ void Binding::installFabricUIManager(
// Keep reference to config object and cache some feature flags here
reactNativeConfig_ = config;
contextContainer->insert(
"CalculateTransformedFramesEnabled",
getFeatureFlagValue("calculateTransformedFramesEnabled"));
CoreFeatures::enablePropIteratorSetter =
getFeatureFlagValue("enableCppPropsIteratorSetter");
CoreFeatures::excludeYogaFromRawProps =
@@ -19,57 +19,6 @@ namespace facebook::react {
template <class T>
using LayoutableSmallVector = std::vector<T>;
static LayoutableSmallVector<Rect> calculateTransformedFrames(
const LayoutableSmallVector<const ShadowNode*>& shadowNodeList,
LayoutableShadowNode::LayoutInspectingPolicy policy) {
auto size = shadowNodeList.size();
auto transformedFrames = LayoutableSmallVector<Rect>{size};
auto transformation = Transform::Identity();
for (auto i = size; i > 0; --i) {
auto currentShadowNode =
dynamic_cast<const LayoutableShadowNode*>(shadowNodeList.at(i - 1));
auto currentFrame = currentShadowNode->getLayoutMetrics().frame;
if (policy.includeTransform) {
if (Transform::isVerticalInversion(transformation)) {
auto parentShadowNode =
dynamic_cast<const LayoutableShadowNode*>(shadowNodeList.at(i));
currentFrame.origin.y =
parentShadowNode->getLayoutMetrics().frame.size.height -
currentFrame.size.height - currentFrame.origin.y;
}
if (Transform::isHorizontalInversion(transformation)) {
auto parentShadowNode =
dynamic_cast<const LayoutableShadowNode*>(shadowNodeList.at(i));
currentFrame.origin.x =
parentShadowNode->getLayoutMetrics().frame.size.width -
currentFrame.size.width - currentFrame.origin.x;
}
if (i != size) {
auto parentShadowNode =
dynamic_cast<const LayoutableShadowNode*>(shadowNodeList.at(i));
auto contentOriginOffset = parentShadowNode->getContentOriginOffset();
if (Transform::isVerticalInversion(transformation)) {
contentOriginOffset.y = -contentOriginOffset.y;
}
if (Transform::isHorizontalInversion(transformation)) {
contentOriginOffset.x = -contentOriginOffset.x;
}
currentFrame.origin += contentOriginOffset;
}
transformation = transformation * currentShadowNode->getTransform();
}
transformedFrames[i - 1] = currentFrame;
}
return transformedFrames;
}
LayoutableShadowNode::LayoutableShadowNode(
const ShadowNodeFragment& fragment,
const ShadowNodeFamily::Shared& family,
@@ -157,22 +106,6 @@ LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics(
return EmptyLayoutMetrics;
}
// ------------------------------
// TODO: T127619309 remove after validating that T127619309 is fixed
auto optionalCalculateTransformedFrames =
descendantNode->getContextContainer()
? descendantNode->getContextContainer()->find<bool>(
"CalculateTransformedFramesEnabled")
: std::optional<bool>(false);
bool shouldCalculateTransformedFrames =
optionalCalculateTransformedFrames.has_value()
? optionalCalculateTransformedFrames.value()
: false;
auto transformedFrames = shouldCalculateTransformedFrames
? calculateTransformedFrames(shadowNodeList, policy)
: LayoutableSmallVector<Rect>();
auto layoutMetrics = descendantLayoutableNode->getLayoutMetrics();
auto& resultFrame = layoutMetrics.frame;
resultFrame.origin = {0, 0};
@@ -194,9 +127,7 @@ LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics(
return EmptyLayoutMetrics;
}
auto currentFrame = shouldCalculateTransformedFrames
? transformedFrames[i]
: currentShadowNode->getLayoutMetrics().frame;
auto currentFrame = currentShadowNode->getLayoutMetrics().frame;
if (i == size - 1) {
// If it's the last element, its origin is irrelevant.
currentFrame.origin = {0, 0};
@@ -219,8 +150,7 @@ LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics(
resultFrame, currentFrame.getCenter());
}
if (!shouldCalculateTransformedFrames && i != 0 &&
policy.includeTransform) {
if (i != 0 && policy.includeTransform) {
resultFrame.origin += currentShadowNode->getContentOriginOffset();
}
@@ -11,24 +11,6 @@
using namespace facebook::react;
class LayoutableShadowNodeTest : public ::testing::TestWithParam<bool> {
public:
LayoutableShadowNodeTest()
: builder_(simpleComponentBuilder(createContextContainer())) {}
ContextContainer::Shared createContextContainer() {
auto contextContainer = std::make_shared<ContextContainer>();
contextContainer->insert("CalculateTransformedFramesEnabled", GetParam());
return contextContainer;
}
bool getCalculateTransformedFramesEnabled() {
return GetParam();
}
ComponentBuilder builder_;
};
/*
* ┌────────┐
* │<View> │
@@ -40,7 +22,8 @@ class LayoutableShadowNodeTest : public ::testing::TestWithParam<bool> {
* │ │
* └────────┘
*/
TEST_P(LayoutableShadowNodeTest, relativeLayoutMetrics) {
TEST(LayoutableShadowNodeTest, relativeLayoutMetrics) {
auto builder = simpleComponentBuilder();
auto childShadowNode = std::shared_ptr<ViewShadowNode>{};
// clang-format off
auto element =
@@ -63,7 +46,7 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetrics) {
});
// clang-format on
auto parentShadowNode = builder_.build(element);
auto parentShadowNode = builder.build(element);
auto relativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
@@ -84,7 +67,9 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetrics) {
* │ │
* └───────────────────┘
*/
TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnNodeWithDisplayNone) {
TEST(LayoutableShadowNodeTest, relativeLayoutMetricsOnNodeWithDisplayNone) {
auto builder = simpleComponentBuilder();
// clang-format off
auto element =
Element<ViewShadowNode>()
@@ -97,7 +82,7 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnNodeWithDisplayNone) {
});
// clang-format on
auto shadowNode = builder_.build(element);
auto shadowNode = builder.build(element);
auto relativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
@@ -118,9 +103,10 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnNodeWithDisplayNone) {
* │ │
* └───────────────────┘
*/
TEST_P(
TEST(
LayoutableShadowNodeTest,
relativeLayoutMetricsOnChildrenOfParentWithDisplayNone) {
auto builder = simpleComponentBuilder();
auto childShadowNode = std::shared_ptr<ViewShadowNode>{};
// clang-format off
auto element =
@@ -144,7 +130,7 @@ TEST_P(
});
// clang-format on
auto parentShadowNode = builder_.build(element);
auto parentShadowNode = builder.build(element);
auto relativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
@@ -168,9 +154,10 @@ TEST_P(
* | |
* └──────────────────┘
*/
TEST_P(
TEST(
LayoutableShadowNodeTest,
relativeLayoutMetricsOnOuterParentWithDisplayNone) {
auto builder = simpleComponentBuilder();
auto parentShadowNode = std::shared_ptr<ViewShadowNode>{};
auto childShadowNode = std::shared_ptr<ViewShadowNode>{};
// clang-format off
@@ -204,7 +191,7 @@ TEST_P(
});
// clang-format on
auto outerParentShadowNode = builder_.build(element);
auto outerParentShadowNode = builder.build(element);
auto relativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
@@ -228,7 +215,8 @@ TEST_P(
* │ │
* └─────────┘
*/
TEST_P(LayoutableShadowNodeTest, contentOriginOffset) {
TEST(LayoutableShadowNodeTest, contentOriginOffset) {
auto builder = simpleComponentBuilder();
auto childShadowNode = std::shared_ptr<ViewShadowNode>{};
// clang-format off
auto element =
@@ -254,7 +242,7 @@ TEST_P(LayoutableShadowNodeTest, contentOriginOffset) {
});
// clang-format on
auto parentShadowNode = builder_.build(element);
auto parentShadowNode = builder.build(element);
auto relativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
@@ -283,7 +271,8 @@ TEST_P(LayoutableShadowNodeTest, contentOriginOffset) {
* │ └────────────────┘│
* └────────────────────────┘
*/
TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnTransformedNode) {
TEST(LayoutableShadowNodeTest, relativeLayoutMetricsOnTransformedNode) {
auto builder = simpleComponentBuilder();
auto childShadowNode = std::shared_ptr<ViewShadowNode>{};
// clang-format off
auto element =
@@ -310,7 +299,7 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnTransformedNode) {
});
// clang-format on
auto parentShadowNode = builder_.build(element);
auto parentShadowNode = builder.build(element);
auto relativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
@@ -338,7 +327,8 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnTransformedNode) {
* │ └─────────────────────┘│
* └────────────────────────┘
*/
TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnTransformedParent) {
TEST(LayoutableShadowNodeTest, relativeLayoutMetricsOnTransformedParent) {
auto builder = simpleComponentBuilder();
auto childShadowNode = std::shared_ptr<ViewShadowNode>{};
// clang-format off
auto element =
@@ -374,7 +364,7 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnTransformedParent) {
});
// clang-format on
auto parentShadowNode = builder_.build(element);
auto parentShadowNode = builder.build(element);
auto relativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
@@ -403,7 +393,8 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnTransformedParent) {
* │ └─────────────────────┘│
* └────────────────────────┘
*/
TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnParentWithClipping) {
TEST(LayoutableShadowNodeTest, relativeLayoutMetricsOnParentWithClipping) {
auto builder = simpleComponentBuilder();
auto childShadowNode = std::shared_ptr<ViewShadowNode>{};
// clang-format off
auto element =
@@ -434,7 +425,7 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnParentWithClipping) {
});
// clang-format on
auto parentShadowNode = builder_.build(element);
auto parentShadowNode = builder.build(element);
auto relativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
@@ -469,9 +460,10 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnParentWithClipping) {
* │ └─────────────────────┘│
* └────────────────────────┘
*/
TEST_P(
TEST(
LayoutableShadowNodeTest,
relativeLayoutMetricsOnTransformedParentWithClipping) {
auto builder = simpleComponentBuilder();
auto childShadowNode = std::shared_ptr<ViewShadowNode>{};
// clang-format off
auto element =
@@ -507,7 +499,7 @@ TEST_P(
});
// clang-format on
auto parentShadowNode = builder_.build(element);
auto parentShadowNode = builder.build(element);
auto relativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
@@ -532,7 +524,8 @@ TEST_P(
* │ │
* └────────────────┘
*/
TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnSameNode) {
TEST(LayoutableShadowNodeTest, relativeLayoutMetricsOnSameNode) {
auto builder = simpleComponentBuilder();
// clang-format off
auto element =
Element<ViewShadowNode>()
@@ -544,7 +537,7 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnSameNode) {
});
// clang-format on
auto shadowNode = builder_.build(element);
auto shadowNode = builder.build(element);
auto relativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
@@ -562,7 +555,8 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnSameNode) {
* │ │
* └────────────────┘
*/
TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnSameTransformedNode) {
TEST(LayoutableShadowNodeTest, relativeLayoutMetricsOnSameTransformedNode) {
auto builder = simpleComponentBuilder();
// clang-format off
auto element =
Element<ViewShadowNode>()
@@ -579,7 +573,7 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnSameTransformedNode) {
});
// clang-format on
auto shadowNode = builder_.build(element);
auto shadowNode = builder.build(element);
auto relativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
@@ -600,7 +594,8 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnSameTransformedNode) {
* │ └────────────────┘│
* └────────────────────────┘
*/
TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnClonedNode) {
TEST(LayoutableShadowNodeTest, relativeLayoutMetricsOnClonedNode) {
auto builder = simpleComponentBuilder();
auto childShadowNode = std::shared_ptr<ViewShadowNode>{};
// clang-format off
@@ -612,7 +607,7 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnClonedNode) {
});
// clang-format on
auto parentShadowNode = builder_.build(element);
auto parentShadowNode = builder.build(element);
auto clonedChildShadowNode =
std::static_pointer_cast<ViewShadowNode>(childShadowNode->clone({}));
@@ -641,9 +636,10 @@ TEST_P(LayoutableShadowNodeTest, relativeLayoutMetricsOnClonedNode) {
* │ └──────────────────────┘│
* └─────────────────────────┘
*/
TEST_P(
TEST(
LayoutableShadowNodeTest,
relativeLayoutMetricsOnNodesCrossingRootKindNode) {
auto builder = simpleComponentBuilder();
auto childShadowNode = std::shared_ptr<ViewShadowNode>{};
// clang-format off
@@ -667,7 +663,7 @@ TEST_P(
})
});
auto parentShadowNode = builder_.build(element);
auto parentShadowNode = builder.build(element);
auto relativeLayoutMetrics = LayoutableShadowNode::computeRelativeLayoutMetrics(childShadowNode->getFamily(), *parentShadowNode, {});
@@ -677,8 +673,8 @@ TEST_P(
EXPECT_EQ(relativeLayoutMetrics.frame.origin.y, 10);
}
TEST_P(LayoutableShadowNodeTest, includeViewportOffset) {
TEST(LayoutableShadowNodeTest, includeViewportOffset) {
auto builder = simpleComponentBuilder();
auto viewShadowNode = std::shared_ptr<ViewShadowNode>{};
// clang-format off
@@ -695,7 +691,7 @@ TEST_P(LayoutableShadowNodeTest, includeViewportOffset) {
});
// clang-format on
auto rootShadowNode = builder_.build(element);
auto rootShadowNode = builder.build(element);
// `includeViewportOffset` has to work with `includeTransform` enabled and
// disabled.
@@ -728,7 +724,8 @@ TEST_P(LayoutableShadowNodeTest, includeViewportOffset) {
* │└─────────────────────────────┘│
* └───────────────────────────────┘
*/
TEST_P(LayoutableShadowNodeTest, invertedVerticalView) {
TEST(LayoutableShadowNodeTest, invertedVerticalView) {
auto builder = simpleComponentBuilder();
auto childShadowNode1 = std::shared_ptr<ViewShadowNode>{};
auto childShadowNode2 = std::shared_ptr<ViewShadowNode>{};
@@ -764,19 +761,14 @@ TEST_P(LayoutableShadowNodeTest, invertedVerticalView) {
});
// clang-format on
auto scrollShadowNode = builder_.build(element);
auto scrollShadowNode = builder.build(element);
auto firstItemRelativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
childShadowNode1->getFamily(), *scrollShadowNode, {});
if (getCalculateTransformedFramesEnabled()) {
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.y, 0);
} else {
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.y, 100);
}
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.x, 0);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.y, 100);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.size.width, 100);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.size.height, 100);
@@ -784,13 +776,8 @@ TEST_P(LayoutableShadowNodeTest, invertedVerticalView) {
LayoutableShadowNode::computeRelativeLayoutMetrics(
childShadowNode2->getFamily(), *scrollShadowNode, {});
if (getCalculateTransformedFramesEnabled()) {
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.origin.y, 100);
} else {
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.origin.y, 0);
}
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.origin.x, 0);
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.origin.y, 0);
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.size.width, 100);
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.size.height, 100);
}
@@ -813,7 +800,8 @@ TEST_P(LayoutableShadowNodeTest, invertedVerticalView) {
* │ └───────────────────────────────┘ │
* └────────────────────────────────────┘
*/
TEST_P(LayoutableShadowNodeTest, nestedInvertedVerticalView) {
TEST(LayoutableShadowNodeTest, nestedInvertedVerticalView) {
auto builder = simpleComponentBuilder();
auto childShadowNode1 = std::shared_ptr<ViewShadowNode>{};
auto childShadowNode2 = std::shared_ptr<ViewShadowNode>{};
@@ -858,17 +846,13 @@ TEST_P(LayoutableShadowNodeTest, nestedInvertedVerticalView) {
});
// clang-format on
auto scrollShadowNode = builder_.build(element);
auto scrollShadowNode = builder.build(element);
auto firstItemRelativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
childShadowNode1->getFamily(), *scrollShadowNode, {});
if (getCalculateTransformedFramesEnabled()) {
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.y, 50);
} else {
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.y, 250);
}
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.y, 250);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.x, 100);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.size.width, 100);
@@ -884,6 +868,94 @@ TEST_P(LayoutableShadowNodeTest, nestedInvertedVerticalView) {
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.size.height, 100);
}
/*
* ┌────────────────────────────────────┐
* │ <View verticallyInverted> │
* │ │
* │ ┌───────────────────────────────┐ │
* │ │ <View verticallyInverted> │ │
* │ │ │ │
* │ │┌─────────────────────────────┐│ │
* │ ││<View childShadowNode1> ││ │
* │ ││ ││ │
* │ │└─────────────────────────────┘│ │
* │ │┌─────────────────────────────┐│ │
* │ ││<View childShadowNode2> ││ │
* │ ││ ││ │
* │ │└─────────────────────────────┘│ │
* │ └───────────────────────────────┘ │
* └────────────────────────────────────┘
*/
TEST(LayoutableShadowNodeTest, nestedDoubleInvertedVerticalView) {
auto builder = simpleComponentBuilder();
auto childShadowNode1 = std::shared_ptr<ViewShadowNode>{};
auto childShadowNode2 = std::shared_ptr<ViewShadowNode>{};
// clang-format off
auto element =
Element<ViewShadowNode>()
.props([] {
auto sharedProps = std::make_shared<ViewShadowNodeProps>();
sharedProps->transform = Transform::VerticalInversion(); // Inverted
return sharedProps;
})
.finalize([](ViewShadowNode &shadowNode){
auto layoutMetrics = EmptyLayoutMetrics;
layoutMetrics.frame.size = {100, 300};
shadowNode.setLayoutMetrics(layoutMetrics);
})
.children({
Element<ViewShadowNode>()
.finalize([](ViewShadowNode &shadowNode){
auto layoutMetrics = EmptyLayoutMetrics;
layoutMetrics.frame.size = {100, 200};
shadowNode.setLayoutMetrics(layoutMetrics);
}).props([] {
auto sharedProps = std::make_shared<ViewShadowNodeProps>();
sharedProps->transform = Transform::VerticalInversion(); // Inverted
return sharedProps;
}).children({
Element<ViewShadowNode>()
.reference(childShadowNode1)
.finalize([](ViewShadowNode &shadowNode){
auto layoutMetrics = EmptyLayoutMetrics;
layoutMetrics.frame.origin = {0, 0};
layoutMetrics.frame.size = {100, 100};
shadowNode.setLayoutMetrics(layoutMetrics);
}),
Element<ViewShadowNode>()
.reference(childShadowNode2)
.finalize([](ViewShadowNode &shadowNode){
auto layoutMetrics = EmptyLayoutMetrics;
layoutMetrics.frame.origin = {0, 100};
layoutMetrics.frame.size = {100, 100};
shadowNode.setLayoutMetrics(layoutMetrics);
})
})
});
// clang-format on
auto scrollShadowNode = builder.build(element);
auto firstItemRelativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
childShadowNode1->getFamily(), *scrollShadowNode, {});
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.x, 0);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.y, 100);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.size.width, 100);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.size.height, 100);
auto secondItemRelativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
childShadowNode2->getFamily(), *scrollShadowNode, {});
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.origin.x, 0);
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.origin.y, 200);
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.size.width, 100);
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.size.height, 100);
}
/*
* ┌──────────────────────────────────────┐
* │ <View horizontallyInverted> │
@@ -894,7 +966,8 @@ TEST_P(LayoutableShadowNodeTest, nestedInvertedVerticalView) {
* │└─────────────────┘└─────────────────┘│
* └──────────────────────────────────────┘
*/
TEST_P(LayoutableShadowNodeTest, invertedHorizontalView) {
TEST(LayoutableShadowNodeTest, invertedHorizontalView) {
auto builder = simpleComponentBuilder();
auto childShadowNode1 = std::shared_ptr<ViewShadowNode>{};
auto childShadowNode2 = std::shared_ptr<ViewShadowNode>{};
@@ -930,19 +1003,13 @@ TEST_P(LayoutableShadowNodeTest, invertedHorizontalView) {
});
// clang-format on
auto scrollShadowNode = builder_.build(element);
auto scrollShadowNode = builder.build(element);
auto firstItemRelativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
childShadowNode1->getFamily(), *scrollShadowNode, {});
if (getCalculateTransformedFramesEnabled()) {
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.x, 0);
} else {
// Incorrect legacy behaviour
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.x, 100);
}
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.x, 100);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.y, 0);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.size.width, 100);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.size.height, 100);
@@ -950,12 +1017,8 @@ TEST_P(LayoutableShadowNodeTest, invertedHorizontalView) {
auto secondItemRelativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
childShadowNode2->getFamily(), *scrollShadowNode, {});
if (getCalculateTransformedFramesEnabled()) {
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.origin.x, 100);
} else {
// Incorrect legacy behaviour
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.origin.x, 0);
}
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.origin.x, 0);
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.origin.y, 0);
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.size.width, 100);
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.size.height, 100);
@@ -975,7 +1038,8 @@ TEST_P(LayoutableShadowNodeTest, invertedHorizontalView) {
* │ └──────────────────────────────────────┘ │
* └──────────────────────────────────────────┘
*/
TEST_P(LayoutableShadowNodeTest, nestedInvertedHorizontalView) {
TEST(LayoutableShadowNodeTest, nestedInvertedHorizontalView) {
auto builder = simpleComponentBuilder();
auto childShadowNode1 = std::shared_ptr<ViewShadowNode>{};
auto childShadowNode2 = std::shared_ptr<ViewShadowNode>{};
@@ -1020,18 +1084,13 @@ TEST_P(LayoutableShadowNodeTest, nestedInvertedHorizontalView) {
});
// clang-format on
auto scrollShadowNode = builder_.build(element);
auto scrollShadowNode = builder.build(element);
auto firstItemRelativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
childShadowNode1->getFamily(), *scrollShadowNode, {});
if (getCalculateTransformedFramesEnabled()) {
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.x, 50);
} else {
// Incorrect legacy behaviour
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.x, 250);
}
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.x, 250);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.origin.y, 100);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.size.width, 100);
EXPECT_EQ(firstItemRelativeLayoutMetrics.frame.size.height, 100);
@@ -1046,7 +1105,8 @@ TEST_P(LayoutableShadowNodeTest, nestedInvertedHorizontalView) {
EXPECT_EQ(secondItemRelativeLayoutMetrics.frame.size.height, 100);
}
TEST_P(LayoutableShadowNodeTest, inversedContentOriginOffset) {
TEST(LayoutableShadowNodeTest, inversedContentOriginOffset) {
auto builder = simpleComponentBuilder();
auto childShadowNode = std::shared_ptr<ViewShadowNode>{};
// clang-format off
@@ -1077,23 +1137,12 @@ TEST_P(LayoutableShadowNodeTest, inversedContentOriginOffset) {
});
// clang-format on
auto parentShadowNode = builder_.build(element);
auto parentShadowNode = builder.build(element);
auto relativeLayoutMetrics =
LayoutableShadowNode::computeRelativeLayoutMetrics(
childShadowNode->getFamily(), *parentShadowNode, {});
if (getCalculateTransformedFramesEnabled()) {
EXPECT_EQ(relativeLayoutMetrics.frame.origin.x, 20);
EXPECT_EQ(relativeLayoutMetrics.frame.origin.y, 20);
} else {
// Incorrect legacy behaviour
EXPECT_EQ(relativeLayoutMetrics.frame.origin.x, 160);
EXPECT_EQ(relativeLayoutMetrics.frame.origin.y, 90);
}
EXPECT_EQ(relativeLayoutMetrics.frame.origin.x, 160);
EXPECT_EQ(relativeLayoutMetrics.frame.origin.y, 90);
}
INSTANTIATE_TEST_SUITE_P(
CalculateTransformedFrames,
LayoutableShadowNodeTest,
testing::Values(false, true));