Skip to content

Commit

Permalink
Fabric: View Test: Changing state should not dirty Yoga tree (in some…
Browse files Browse the repository at this point in the history
… most cases)

Summary: Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20578789

fbshipit-source-id: 4336165217bd39fc8065cfaeb96ef7753433d48a
  • Loading branch information
shergin authored and facebook-github-bot committed Mar 23, 2020
1 parent 100bf90 commit 0952e4b
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion ReactCommon/fabric/components/view/tests/ViewTest.cpp
Expand Up @@ -18,7 +18,8 @@
#include <react/element/testUtils.h>
#include <react/uimanager/ComponentDescriptorProviderRegistry.h>

using namespace facebook::react;
namespace facebook {
namespace react {

class YogaDirtyFlagTest : public ::testing::Test {
protected:
Expand Down Expand Up @@ -191,3 +192,30 @@ TEST_F(YogaDirtyFlagTest, reversingListOfChildrenMustDirtyYogaNode) {
EXPECT_TRUE(
static_cast<RootShadowNode &>(*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<ScrollViewState>(state));

return oldShadowNode.clone({ShadowNodeFragment::propsPlaceholder(),
ShadowNodeFragment::childrenPlaceholder(),
newState});
});

EXPECT_FALSE(
static_cast<RootShadowNode &>(*newRootShadowNode).layoutIfNeeded());
}

} // namespace react
} // namespace facebook

0 comments on commit 0952e4b

Please sign in to comment.