2018-11-06 10:58:51 -08:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#include "UIManager.h"
|
|
|
|
|
|
|
|
#include <fabric/core/ShadowNodeFragment.h>
|
2018-11-08 16:55:12 -08:00
|
|
|
#include <fabric/debug/SystraceSection.h>
|
2018-11-06 10:58:51 -08:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
SharedShadowNode UIManager::createNode(
|
|
|
|
Tag tag,
|
|
|
|
const ComponentName &name,
|
|
|
|
SurfaceId surfaceId,
|
|
|
|
const RawProps &rawProps,
|
|
|
|
SharedEventTarget eventTarget) const {
|
|
|
|
auto &componentDescriptor = componentDescriptorRegistry_->at(name);
|
|
|
|
|
|
|
|
auto shadowNode = componentDescriptor.createShadowNode(
|
|
|
|
{.tag = tag,
|
|
|
|
.rootTag = surfaceId,
|
|
|
|
.eventEmitter =
|
|
|
|
componentDescriptor.createEventEmitter(std::move(eventTarget), tag),
|
|
|
|
.props = componentDescriptor.cloneProps(nullptr, rawProps)});
|
|
|
|
|
|
|
|
if (delegate_) {
|
|
|
|
delegate_->uiManagerDidCreateShadowNode(shadowNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::const_pointer_cast<ShadowNode>(shadowNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedShadowNode UIManager::cloneNode(
|
|
|
|
const SharedShadowNode &shadowNode,
|
|
|
|
const SharedShadowNodeSharedList &children,
|
|
|
|
const folly::Optional<RawProps> &rawProps) const {
|
|
|
|
auto &componentDescriptor =
|
|
|
|
componentDescriptorRegistry_->at(shadowNode->getComponentHandle());
|
|
|
|
|
|
|
|
auto clonedShadowNode = componentDescriptor.cloneShadowNode(
|
|
|
|
*shadowNode,
|
|
|
|
{
|
|
|
|
.props = rawProps.has_value()
|
|
|
|
? componentDescriptor.cloneProps(
|
|
|
|
shadowNode->getProps(), rawProps.value())
|
|
|
|
: ShadowNodeFragment::nullSharedProps(),
|
|
|
|
.children = children,
|
|
|
|
});
|
|
|
|
|
|
|
|
return std::const_pointer_cast<ShadowNode>(clonedShadowNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIManager::appendChild(
|
|
|
|
const SharedShadowNode &parentShadowNode,
|
|
|
|
const SharedShadowNode &childShadowNode) const {
|
|
|
|
auto &componentDescriptor =
|
|
|
|
componentDescriptorRegistry_->at(parentShadowNode->getComponentHandle());
|
|
|
|
componentDescriptor.appendChild(parentShadowNode, childShadowNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIManager::completeSurface(
|
|
|
|
SurfaceId surfaceId,
|
|
|
|
const SharedShadowNodeUnsharedList &rootChildren) const {
|
2018-11-08 16:55:12 -08:00
|
|
|
SystraceSection s("FabricUIManager::completeSurface");
|
2018-11-06 10:58:51 -08:00
|
|
|
if (delegate_) {
|
|
|
|
delegate_->uiManagerDidFinishTransaction(surfaceId, rootChildren);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIManager::setComponentDescriptorRegistry(
|
|
|
|
const SharedComponentDescriptorRegistry &componentDescriptorRegistry) {
|
|
|
|
componentDescriptorRegistry_ = componentDescriptorRegistry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIManager::setDelegate(UIManagerDelegate *delegate) {
|
|
|
|
delegate_ = delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
UIManagerDelegate *UIManager::getDelegate() {
|
|
|
|
return delegate_;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|