diff --git a/ReactCommon/fabric/mounting/ShadowTree.cpp b/ReactCommon/fabric/mounting/ShadowTree.cpp index 59d414943e9..66e91f5dde7 100644 --- a/ReactCommon/fabric/mounting/ShadowTree.cpp +++ b/ReactCommon/fabric/mounting/ShadowTree.cpp @@ -129,14 +129,16 @@ MountingCoordinator::Shared ShadowTree::getMountingCoordinator() const { return mountingCoordinator_; } -void ShadowTree::commit(ShadowTreeCommitTransaction transaction) const { +void ShadowTree::commit( + ShadowTreeCommitTransaction transaction, + bool enableStateReconciliation) const { SystraceSection s("ShadowTree::commit"); int attempts = 0; while (true) { attempts++; - if (tryCommit(transaction)) { + if (tryCommit(transaction, enableStateReconciliation)) { return; } @@ -146,7 +148,9 @@ void ShadowTree::commit(ShadowTreeCommitTransaction transaction) const { } } -bool ShadowTree::tryCommit(ShadowTreeCommitTransaction transaction) const { +bool ShadowTree::tryCommit( + ShadowTreeCommitTransaction transaction, + bool enableStateReconciliation) const { SystraceSection s("ShadowTree::tryCommit"); auto telemetry = MountingTelemetry{}; @@ -168,11 +172,13 @@ bool ShadowTree::tryCommit(ShadowTreeCommitTransaction transaction) const { // Compare state revisions of old and new root // Children of the root node may be mutated in-place - UnsharedShadowNode reconciledNode = - reconcileStateWithTree(newRootShadowNode.get(), oldRootShadowNode); - if (reconciledNode != nullptr) { - newRootShadowNode = - std::make_shared(*reconciledNode, ShadowNodeFragment{}); + if (enableStateReconciliation) { + UnsharedShadowNode reconciledNode = + reconcileStateWithTree(newRootShadowNode.get(), oldRootShadowNode); + if (reconciledNode != nullptr) { + newRootShadowNode = std::make_shared( + *reconciledNode, ShadowNodeFragment{}); + } } // Layout nodes diff --git a/ReactCommon/fabric/mounting/ShadowTree.h b/ReactCommon/fabric/mounting/ShadowTree.h index bff4840f662..a2e9aaa1742 100644 --- a/ReactCommon/fabric/mounting/ShadowTree.h +++ b/ReactCommon/fabric/mounting/ShadowTree.h @@ -53,12 +53,16 @@ class ShadowTree final { * The `transaction` function can abort commit returning `nullptr`. * Returns `true` if the operation finished successfully. */ - bool tryCommit(ShadowTreeCommitTransaction transaction) const; + bool tryCommit( + ShadowTreeCommitTransaction transaction, + bool enableStateReconciliation = false) const; /* * Calls `tryCommit` in a loop until it finishes successfully. */ - void commit(ShadowTreeCommitTransaction transaction) const; + void commit( + ShadowTreeCommitTransaction transaction, + bool enableStateReconciliation = false) const; /* * Commit an empty tree (a new `RootShadowNode` with no children). diff --git a/ReactCommon/fabric/uimanager/Scheduler.cpp b/ReactCommon/fabric/uimanager/Scheduler.cpp index a4be7904234..70746d146fb 100644 --- a/ReactCommon/fabric/uimanager/Scheduler.cpp +++ b/ReactCommon/fabric/uimanager/Scheduler.cpp @@ -67,6 +67,15 @@ Scheduler::Scheduler( uiManager->setDelegate(this); uiManager->setComponentDescriptorRegistry(componentDescriptorRegistry_); +#ifdef ANDROID + bool stateReconciliationEnabled = reactNativeConfig_->getBool( + "react_fabric:enabled_state_reconciliation_android"); +#else + bool stateReconciliationEnabled = reactNativeConfig_->getBool( + "react_fabric:enabled_state_reconciliation_ios"); +#endif + uiManager->setStateReconciliationEnabled(stateReconciliationEnabled); + runtimeExecutor_([=](jsi::Runtime &runtime) { auto uiManagerBinding = UIManagerBinding::createAndInstallIfNeeded(runtime); uiManagerBinding->attach(uiManager); diff --git a/ReactCommon/fabric/uimanager/UIManager.cpp b/ReactCommon/fabric/uimanager/UIManager.cpp index 990cb0294b7..849b3450ae9 100644 --- a/ReactCommon/fabric/uimanager/UIManager.cpp +++ b/ReactCommon/fabric/uimanager/UIManager.cpp @@ -109,17 +109,23 @@ void UIManager::completeSurface( SystraceSection s("UIManager::completeSurface"); shadowTreeRegistry_.visit(surfaceId, [&](ShadowTree const &shadowTree) { - shadowTree.commit([&](RootShadowNode::Shared const &oldRootShadowNode) { - return std::make_shared( - *oldRootShadowNode, - ShadowNodeFragment{ - /* .props = */ ShadowNodeFragment::propsPlaceholder(), - /* .children = */ rootChildren, - }); - }); + shadowTree.commit( + [&](RootShadowNode::Shared const &oldRootShadowNode) { + return std::make_shared( + *oldRootShadowNode, + ShadowNodeFragment{ + /* .props = */ ShadowNodeFragment::propsPlaceholder(), + /* .children = */ rootChildren, + }); + }, + true && stateReconciliationEnabled_); }); } +void UIManager::setStateReconciliationEnabled(bool enabled) { + stateReconciliationEnabled_ = enabled; +} + void UIManager::setJSResponder( const ShadowNode::Shared &shadowNode, const bool blockNativeResponder) const { @@ -159,7 +165,8 @@ void UIManager::setNativeProps( /* .props = */ props, }); }); - }); + }, + true && stateReconciliationEnabled_); }); } @@ -176,7 +183,8 @@ LayoutMetrics UIManager::getRelativeLayoutMetrics( [&](RootShadowNode::Shared const &oldRootShadowNode) { ancestorShadowNode = oldRootShadowNode.get(); return nullptr; - }); + }, + true && stateReconciliationEnabled_); }); } diff --git a/ReactCommon/fabric/uimanager/UIManager.h b/ReactCommon/fabric/uimanager/UIManager.h index 4f47d7702d7..fccae0f0407 100644 --- a/ReactCommon/fabric/uimanager/UIManager.h +++ b/ReactCommon/fabric/uimanager/UIManager.h @@ -55,6 +55,8 @@ class UIManager final : public ShadowTreeDelegate { ShadowTree const &shadowTree, MountingCoordinator::Shared const &mountingCoordinator) const override; + void setStateReconciliationEnabled(bool enabled); + private: friend class UIManagerBinding; friend class Scheduler; @@ -121,6 +123,7 @@ class UIManager final : public ShadowTreeDelegate { UIManagerDelegate *delegate_; UIManagerBinding *uiManagerBinding_; ShadowTreeRegistry shadowTreeRegistry_{}; + bool stateReconciliationEnabled_{false}; }; } // namespace react