From 0952e4bb03c88f34fb27db7bd80a2fc971eaee0c Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 23 Mar 2020 13:28:46 -0700 Subject: [PATCH] Fabric: View Test: Changing state should not dirty Yoga tree (in some most cases) Summary: Changelog: [Internal] Fabric-specific internal change. Reviewed By: mdvacca Differential Revision: D20578789 fbshipit-source-id: 4336165217bd39fc8065cfaeb96ef7753433d48a --- .../fabric/components/view/tests/ViewTest.cpp | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/ReactCommon/fabric/components/view/tests/ViewTest.cpp b/ReactCommon/fabric/components/view/tests/ViewTest.cpp index 15bfea1fafc..32aff667905 100644 --- a/ReactCommon/fabric/components/view/tests/ViewTest.cpp +++ b/ReactCommon/fabric/components/view/tests/ViewTest.cpp @@ -18,7 +18,8 @@ #include #include -using namespace facebook::react; +namespace facebook { +namespace react { class YogaDirtyFlagTest : public ::testing::Test { protected: @@ -191,3 +192,30 @@ TEST_F(YogaDirtyFlagTest, reversingListOfChildrenMustDirtyYogaNode) { EXPECT_TRUE( static_cast(*newRootShadowNode).layoutIfNeeded()); } + +TEST_F(YogaDirtyFlagTest, updatingStateForScrollViewMistNotDirtyYogaNode) { + /* + * Updating a state for *some* (not all!) components must *not* dirty Yoga + * nodes. + */ + auto newRootShadowNode = rootShadowNode_->cloneTree( + scrollViewShadowNode_->getFamily(), [](ShadowNode const &oldShadowNode) { + auto state = ScrollViewState{}; + state.contentOffset = Point{42, 9000}; + + auto &componentDescriptor = oldShadowNode.getComponentDescriptor(); + auto newState = componentDescriptor.createState( + oldShadowNode.getFamily(), + std::make_shared(state)); + + return oldShadowNode.clone({ShadowNodeFragment::propsPlaceholder(), + ShadowNodeFragment::childrenPlaceholder(), + newState}); + }); + + EXPECT_FALSE( + static_cast(*newRootShadowNode).layoutIfNeeded()); +} + +} // namespace react +} // namespace facebook