From ebdce9b3b07b5134e185f13d7c3edeee304afbbd Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sun, 15 Dec 2019 18:49:31 -0800 Subject: [PATCH] Fabric: SafeAreaView does always not dirty Yoga node during cloning anymore Summary: Setting `padding` for Yoga node dirties it. In the previous implementation, we did it for all newly cloned nodes. Now we do it only if State actually changes. This is important because usually, SafeAreaView is a container node; that means that if some descendant of SafeAreaView changes its state, the recloning of all nodes down to root node will cause dirtying SafeAreaView and cause relayout if the whole subtree. E.g., if we put ScrollView inside SafeAreaView without the fix, onScroll events will cause Yoga relayout (because ScrollView updates own state on debounced onScroll event). Changelog: [Internal] Fabric-specific internal change. Reviewed By: JoshuaGross Differential Revision: D18987158 fbshipit-source-id: a3130c607c37e54ce813113222cd4a3872c58b6a --- .../safeareaview/SafeAreaViewComponentDescriptor.h | 5 ++++- .../fabric/components/safeareaview/SafeAreaViewShadowNode.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ReactCommon/fabric/components/safeareaview/SafeAreaViewComponentDescriptor.h b/ReactCommon/fabric/components/safeareaview/SafeAreaViewComponentDescriptor.h index aac036f2d01..23b1e37c289 100644 --- a/ReactCommon/fabric/components/safeareaview/SafeAreaViewComponentDescriptor.h +++ b/ReactCommon/fabric/components/safeareaview/SafeAreaViewComponentDescriptor.h @@ -35,7 +35,10 @@ class SafeAreaViewComponentDescriptor final shadowNode->getState()); auto stateData = state->getData(); - layoutableShadowNode->setPadding(stateData.padding); + if (safeAreaViewShadowNode->alreadyAppliedPadding != stateData.padding) { + safeAreaViewShadowNode->alreadyAppliedPadding = stateData.padding; + layoutableShadowNode->setPadding(stateData.padding); + } ConcreteComponentDescriptor::adopt(shadowNode); } diff --git a/ReactCommon/fabric/components/safeareaview/SafeAreaViewShadowNode.h b/ReactCommon/fabric/components/safeareaview/SafeAreaViewShadowNode.h index 44970270ef0..27df74ffaba 100644 --- a/ReactCommon/fabric/components/safeareaview/SafeAreaViewShadowNode.h +++ b/ReactCommon/fabric/components/safeareaview/SafeAreaViewShadowNode.h @@ -26,6 +26,9 @@ class SafeAreaViewShadowNode final : public ConcreteViewShadowNode< ViewEventEmitter, SafeAreaViewState> { using ConcreteViewShadowNode::ConcreteViewShadowNode; + + public: + EdgeInsets alreadyAppliedPadding{}; }; } // namespace react