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
This commit is contained in:
Valentin Shergin 2018-11-27 18:01:01 -08:00 committed by Facebook Github Bot
parent f42d2b9e32
commit 142dd7673e
2 changed files with 30 additions and 1 deletions

View File

@ -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> &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) {

View File

@ -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