From 142dd7673e279c9620b99cd55788f39d8525cf9f Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 27 Nov 2018 18:01:01 -0800 Subject: [PATCH] Fabric: UIManager::setNativeProps Summary: Pretty straightforward wiring UIManager and the new feature in ShadowTree: we get the node, clone with the new props and then replace this. Reviewed By: sahrens Differential Revision: D13114788 fbshipit-source-id: 3a34fb879f3ec564c26278034a19b88518302de8 --- ReactCommon/fabric/uimanager/UIManager.cpp | 27 +++++++++++++++++++++- ReactCommon/fabric/uimanager/UIManager.h | 4 ++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ReactCommon/fabric/uimanager/UIManager.cpp b/ReactCommon/fabric/uimanager/UIManager.cpp index ff29c5f7e1f..16a7ffbeb9b 100644 --- a/ReactCommon/fabric/uimanager/UIManager.cpp +++ b/ReactCommon/fabric/uimanager/UIManager.cpp @@ -14,6 +14,8 @@ SharedShadowNode UIManager::createNode( SurfaceId surfaceId, const RawProps &rawProps, SharedEventTarget eventTarget) const { + SystraceSection s("UIManager::createNode"); + auto &componentDescriptor = componentDescriptorRegistry_->at(name); auto shadowNode = componentDescriptor.createShadowNode( @@ -34,6 +36,8 @@ SharedShadowNode UIManager::cloneNode( const SharedShadowNode &shadowNode, const SharedShadowNodeSharedList &children, const folly::Optional &rawProps) const { + SystraceSection s("UIManager::cloneNode"); + auto &componentDescriptor = componentDescriptorRegistry_->at(shadowNode->getComponentHandle()); @@ -53,6 +57,8 @@ SharedShadowNode UIManager::cloneNode( void UIManager::appendChild( const SharedShadowNode &parentShadowNode, const SharedShadowNode &childShadowNode) const { + SystraceSection s("UIManager::appendChild"); + auto &componentDescriptor = componentDescriptorRegistry_->at(parentShadowNode->getComponentHandle()); componentDescriptor.appendChild(parentShadowNode, childShadowNode); @@ -61,15 +67,34 @@ void UIManager::appendChild( void UIManager::completeSurface( SurfaceId surfaceId, const SharedShadowNodeUnsharedList &rootChildren) const { - SystraceSection s("FabricUIManager::completeSurface"); + SystraceSection s("UIManager::completeSurface"); + if (delegate_) { delegate_->uiManagerDidFinishTransaction(surfaceId, rootChildren); } } +void UIManager::setNativeProps( + const SharedShadowNode &shadowNode, + const RawProps &rawProps) const { + SystraceSection s("UIManager::setNativeProps"); + + auto &componentDescriptor = + componentDescriptorRegistry_->at(shadowNode->getComponentHandle()); + auto props = componentDescriptor.cloneProps(shadowNode->getProps(), rawProps); + auto newShadowNode = shadowNode->clone(ShadowNodeFragment{.props = props}); + + shadowTreeRegistry_->get( + shadowNode->getRootTag(), [&](const ShadowTree &shadowTree) { + shadowTree.completeByReplacingShadowNode(shadowNode, newShadowNode); + }); +} + LayoutMetrics UIManager::getRelativeLayoutMetrics( const ShadowNode &shadowNode, const ShadowNode *ancestorShadowNode) const { + SystraceSection s("UIManager::getRelativeLayoutMetrics"); + if (!ancestorShadowNode) { shadowTreeRegistry_->get( shadowNode.getRootTag(), [&](const ShadowTree &shadowTree) { diff --git a/ReactCommon/fabric/uimanager/UIManager.h b/ReactCommon/fabric/uimanager/UIManager.h index 33742a6d7e4..462300265cc 100644 --- a/ReactCommon/fabric/uimanager/UIManager.h +++ b/ReactCommon/fabric/uimanager/UIManager.h @@ -52,6 +52,10 @@ class UIManager { SurfaceId surfaceId, const SharedShadowNodeUnsharedList &rootChildren) const; + void setNativeProps( + const SharedShadowNode &shadowNode, + const RawProps &rawProps) const; + /* * Returns layout metrics of given `shadowNode` relative to * `ancestorShadowNode` (relative to the root node in case if provided