Skip to content

Commit 0952e4b

Browse files
sherginfacebook-github-bot
authored andcommitted
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
1 parent 100bf90 commit 0952e4b

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

ReactCommon/fabric/components/view/tests/ViewTest.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
#include <react/element/testUtils.h>
1919
#include <react/uimanager/ComponentDescriptorProviderRegistry.h>
2020

21-
using namespace facebook::react;
21+
namespace facebook {
22+
namespace react {
2223

2324
class YogaDirtyFlagTest : public ::testing::Test {
2425
protected:
@@ -191,3 +192,30 @@ TEST_F(YogaDirtyFlagTest, reversingListOfChildrenMustDirtyYogaNode) {
191192
EXPECT_TRUE(
192193
static_cast<RootShadowNode &>(*newRootShadowNode).layoutIfNeeded());
193194
}
195+
196+
TEST_F(YogaDirtyFlagTest, updatingStateForScrollViewMistNotDirtyYogaNode) {
197+
/*
198+
* Updating a state for *some* (not all!) components must *not* dirty Yoga
199+
* nodes.
200+
*/
201+
auto newRootShadowNode = rootShadowNode_->cloneTree(
202+
scrollViewShadowNode_->getFamily(), [](ShadowNode const &oldShadowNode) {
203+
auto state = ScrollViewState{};
204+
state.contentOffset = Point{42, 9000};
205+
206+
auto &componentDescriptor = oldShadowNode.getComponentDescriptor();
207+
auto newState = componentDescriptor.createState(
208+
oldShadowNode.getFamily(),
209+
std::make_shared<ScrollViewState>(state));
210+
211+
return oldShadowNode.clone({ShadowNodeFragment::propsPlaceholder(),
212+
ShadowNodeFragment::childrenPlaceholder(),
213+
newState});
214+
});
215+
216+
EXPECT_FALSE(
217+
static_cast<RootShadowNode &>(*newRootShadowNode).layoutIfNeeded());
218+
}
219+
220+
} // namespace react
221+
} // namespace facebook

0 commit comments

Comments
 (0)