mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 07:08:27 +00:00
Summary: This diff changes how we expose UIManager to JavaScript realm and control ownership of it. This change should improve reliability and a thread-safety. UIManagerBinding is a HostObject which consolidate ownership of UIManager. Now JavaScript's GC controls its lifetime which eliminates the possibility of calling some JS facing methods of UIManager using a dangling pointer. Besides that, all API now imply that if the caller has a reference to jsi::Runtime, it calls the method on the proper thread (it's an implication of RuntimeExecutor design). Reviewed By: sahrens Differential Revision: D12876745 fbshipit-source-id: eb8c70317460df5b14e45031ad15fc6c8e5b5ce3
83 lines
2.4 KiB
C++
83 lines
2.4 KiB
C++
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
#include "UIManager.h"
|
|
|
|
#include <fabric/core/ShadowNodeFragment.h>
|
|
|
|
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 {
|
|
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
|