`fabric/uimanager` module
Summary: `fabric/uimanager` implements FabricUIModule. Reviewed By: fkgozali Differential Revision: D7230669 fbshipit-source-id: db6228021352598feac7854b5871d9d6c5c85119
This commit is contained in:
parent
965e60b05a
commit
c2ad59a277
|
@ -40,6 +40,7 @@ rn_xplat_cxx_library(
|
||||||
"xplat//folly:molly",
|
"xplat//folly:molly",
|
||||||
"xplat//third-party/glog:glog",
|
"xplat//third-party/glog:glog",
|
||||||
react_native_xplat_target("fabric/core:core"),
|
react_native_xplat_target("fabric/core:core"),
|
||||||
|
react_native_xplat_target("fabric/uimanager:uimanager"),
|
||||||
react_native_xplat_target("fabric/view:view"),
|
react_native_xplat_target("fabric/view:view"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "FabricUIManager.h"
|
|
||||||
|
|
||||||
#include "IFabricPlatformUIOperationManager.h"
|
|
||||||
|
|
||||||
namespace facebook {
|
|
||||||
namespace react {
|
|
||||||
|
|
||||||
FabricUIManager::FabricUIManager(const std::shared_ptr<IFabricPlatformUIOperationManager> &platformUIOperationManager) :
|
|
||||||
platformUIOperationManager_(platformUIOperationManager) {};
|
|
||||||
|
|
||||||
SharedShadowNode FabricUIManager::createNode(int reactTag, std::string viewName, int rootTag, folly::dynamic props, void *instanceHandle) {
|
|
||||||
platformUIOperationManager_->performUIOperation();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedShadowNode FabricUIManager::cloneNode(const SharedShadowNode &node) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedShadowNode FabricUIManager::cloneNodeWithNewChildren(const SharedShadowNode &node) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedShadowNode FabricUIManager::cloneNodeWithNewProps(const SharedShadowNode &node, folly::dynamic props) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedShadowNode FabricUIManager::cloneNodeWithNewChildrenAndProps(const SharedShadowNode &node, folly::dynamic newProps) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FabricUIManager::appendChild(const SharedShadowNode &parentNode, const SharedShadowNode &childNode) {
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedShadowNodeUnsharedList FabricUIManager::createChildSet(int rootTag) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FabricUIManager::appendChildToSet(const SharedShadowNodeUnsharedList &childSet, const SharedShadowNode &childNode) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void FabricUIManager::completeRoot(int rootTag, const SharedShadowNodeUnsharedList &childSet) {
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace react
|
|
||||||
} // namespace facebook
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
load("//configurations/buck/apple:flag_defs.bzl", "get_debug_preprocessor_flags")
|
||||||
|
load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "react_native_xplat_target", "rn_xplat_cxx_library", "APPLE_INSPECTOR_FLAGS")
|
||||||
|
|
||||||
|
APPLE_COMPILER_FLAGS = []
|
||||||
|
|
||||||
|
if not IS_OSS_BUILD:
|
||||||
|
load("@xplat//configurations/buck/apple:flag_defs.bzl", "get_static_library_ios_flags", "flags")
|
||||||
|
APPLE_COMPILER_FLAGS = flags.get_flag_value(get_static_library_ios_flags(), 'compiler_flags')
|
||||||
|
|
||||||
|
rn_xplat_cxx_library(
|
||||||
|
name = "uimanager",
|
||||||
|
srcs = glob(
|
||||||
|
[
|
||||||
|
"**/*.cpp",
|
||||||
|
],
|
||||||
|
),
|
||||||
|
headers = glob(
|
||||||
|
[
|
||||||
|
"**/*.h",
|
||||||
|
],
|
||||||
|
),
|
||||||
|
header_namespace = "",
|
||||||
|
exported_headers = subdir_glob(
|
||||||
|
[
|
||||||
|
("", "*.h"),
|
||||||
|
],
|
||||||
|
prefix = "fabric/uimanager",
|
||||||
|
),
|
||||||
|
compiler_flags = [
|
||||||
|
"-fexceptions",
|
||||||
|
"-frtti",
|
||||||
|
"-std=c++14",
|
||||||
|
"-Wall",
|
||||||
|
],
|
||||||
|
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
|
||||||
|
fbobjc_preprocessor_flags = get_debug_preprocessor_flags() + APPLE_INSPECTOR_FLAGS,
|
||||||
|
force_static = True,
|
||||||
|
preprocessor_flags = [
|
||||||
|
"-DLOG_TAG=\"ReactNative\"",
|
||||||
|
"-DWITH_FBSYSTRACE=1",
|
||||||
|
],
|
||||||
|
visibility = ["PUBLIC"],
|
||||||
|
deps = [
|
||||||
|
"xplat//fbsystrace:fbsystrace",
|
||||||
|
"xplat//folly:headers_only",
|
||||||
|
"xplat//folly:memory",
|
||||||
|
"xplat//folly:molly",
|
||||||
|
"xplat//third-party/glog:glog",
|
||||||
|
react_native_xplat_target("fabric/debug:debug"),
|
||||||
|
react_native_xplat_target("fabric/core:core"),
|
||||||
|
],
|
||||||
|
)
|
|
@ -0,0 +1,26 @@
|
||||||
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||||
|
|
||||||
|
#include "ComponentDescriptorRegistry.h"
|
||||||
|
|
||||||
|
namespace facebook {
|
||||||
|
namespace react {
|
||||||
|
|
||||||
|
void ComponentDescriptorRegistry::registerComponentDescriptor(SharedComponentDescriptor componentDescriptor) {
|
||||||
|
ComponentHandle componentHandle = componentDescriptor->getComponentHandle();
|
||||||
|
_registryByHandle[componentHandle] = componentDescriptor;
|
||||||
|
|
||||||
|
ComponentName componentName = componentDescriptor->getComponentName();
|
||||||
|
_registryByName[componentName] = componentDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SharedComponentDescriptor ComponentDescriptorRegistry::operator[](const SharedShadowNode &shadowNode) {
|
||||||
|
ComponentHandle componentHandle = shadowNode->getComponentHandle();
|
||||||
|
return _registryByHandle[componentHandle];
|
||||||
|
}
|
||||||
|
|
||||||
|
const SharedComponentDescriptor ComponentDescriptorRegistry::operator[](const ComponentName &componentName) {
|
||||||
|
return _registryByName[componentName];
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace react
|
||||||
|
} // namespace facebook
|
|
@ -0,0 +1,29 @@
|
||||||
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include <fabric/core/ComponentDescriptor.h>
|
||||||
|
|
||||||
|
namespace facebook {
|
||||||
|
namespace react {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Registry of particular `ComponentDescriptor`s.
|
||||||
|
*/
|
||||||
|
class ComponentDescriptorRegistry {
|
||||||
|
|
||||||
|
public:
|
||||||
|
void registerComponentDescriptor(SharedComponentDescriptor componentDescriptor);
|
||||||
|
|
||||||
|
const SharedComponentDescriptor operator[](const SharedShadowNode &shadowNode);
|
||||||
|
const SharedComponentDescriptor operator[](const ComponentName &componentName);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_map<ComponentHandle, SharedComponentDescriptor> _registryByHandle;
|
||||||
|
std::unordered_map<ComponentName, SharedComponentDescriptor> _registryByName;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace react
|
||||||
|
} // namespace facebook
|
|
@ -0,0 +1,109 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2015-present, Facebook, Inc.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "FabricUIManager.h"
|
||||||
|
|
||||||
|
#include <fabric/core/LayoutContext.h>
|
||||||
|
#include <fabric/view/ViewComponentDescriptor.h>
|
||||||
|
#include <fabric/view/ViewProps.h>
|
||||||
|
#include <fabric/view/ViewShadowNode.h>
|
||||||
|
|
||||||
|
#include "IFabricPlatformUIOperationManager.h"
|
||||||
|
|
||||||
|
namespace facebook {
|
||||||
|
namespace react {
|
||||||
|
|
||||||
|
static const RawProps rawPropsFromDynamic(const folly::dynamic object) {
|
||||||
|
// TODO: Convert this to something smarter, probably returning `std::iterator`.
|
||||||
|
RawProps result;
|
||||||
|
|
||||||
|
if (object.isNull()) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(object.isObject());
|
||||||
|
|
||||||
|
for (const auto &pair : object.items()) {
|
||||||
|
assert(pair.first.isString());
|
||||||
|
result[pair.first.asString()] = pair.second;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
FabricUIManager::FabricUIManager(const std::shared_ptr<IFabricPlatformUIOperationManager> &platformUIOperationManager):
|
||||||
|
platformUIOperationManager_(platformUIOperationManager) {
|
||||||
|
|
||||||
|
SharedComponentDescriptor viewComponentDescriptor = std::make_shared<ViewComponentDescriptor>();
|
||||||
|
_registry.registerComponentDescriptor(viewComponentDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedShadowNode FabricUIManager::createNode(int tag, std::string viewName, int rootTag, folly::dynamic props, void *instanceHandle) {
|
||||||
|
ComponentDescriptor &componentDescriptor = *_registry["View"];
|
||||||
|
RawProps rawProps = rawPropsFromDynamic(props);
|
||||||
|
SharedShadowNode shadowNode = componentDescriptor.createShadowNode(tag, rootTag, instanceHandle, rawProps);
|
||||||
|
return shadowNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedShadowNode FabricUIManager::cloneNode(const SharedShadowNode &shadowNode) {
|
||||||
|
ComponentDescriptor &componentDescriptor = *_registry[shadowNode];
|
||||||
|
return componentDescriptor.cloneShadowNode(shadowNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedShadowNode FabricUIManager::cloneNodeWithNewChildren(const SharedShadowNode &shadowNode) {
|
||||||
|
// Assuming semantic: Cloning with same props but empty children.
|
||||||
|
ComponentDescriptor &componentDescriptor = *_registry[shadowNode];
|
||||||
|
return componentDescriptor.cloneShadowNode(shadowNode, nullptr, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedShadowNode FabricUIManager::cloneNodeWithNewProps(const SharedShadowNode &shadowNode, folly::dynamic props) {
|
||||||
|
// Assuming semantic: Cloning with same children and specified props.
|
||||||
|
ComponentDescriptor &componentDescriptor = *_registry[shadowNode];
|
||||||
|
RawProps rawProps = rawPropsFromDynamic(props);
|
||||||
|
return componentDescriptor.cloneShadowNode(shadowNode, std::make_shared<const RawProps>(rawProps), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedShadowNode FabricUIManager::cloneNodeWithNewChildrenAndProps(const SharedShadowNode &shadowNode, folly::dynamic props) {
|
||||||
|
// Assuming semantic: Cloning with empty children and specified props.
|
||||||
|
ComponentDescriptor &componentDescriptor = *_registry[shadowNode];
|
||||||
|
RawProps rawProps = rawPropsFromDynamic(props);
|
||||||
|
return componentDescriptor.cloneShadowNode(shadowNode, std::make_shared<const RawProps>(rawProps), {});
|
||||||
|
}
|
||||||
|
|
||||||
|
void FabricUIManager::appendChild(const SharedShadowNode &parentShadowNode, const SharedShadowNode &childShadowNode) {
|
||||||
|
ComponentDescriptor &componentDescriptor = *_registry[parentShadowNode];
|
||||||
|
componentDescriptor.appendChild(parentShadowNode, childShadowNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedShadowNodeUnsharedList FabricUIManager::createChildSet(int rootTag) {
|
||||||
|
return std::make_shared<SharedShadowNodeList>(SharedShadowNodeList({}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void FabricUIManager::appendChildToSet(const SharedShadowNodeUnsharedList &shadowNodeList, const SharedShadowNode &shadowNode) {
|
||||||
|
shadowNodeList->push_back(shadowNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FabricUIManager::completeRoot(int rootTag, const SharedShadowNodeUnsharedList &children) {
|
||||||
|
ComponentDescriptor &componentDescriptor = *_registry["View"];
|
||||||
|
SharedShadowNode previousRootShadowNode = componentDescriptor.createShadowNode(rootTag, rootTag, nullptr, {});
|
||||||
|
auto childrenCopy = std::make_shared<const SharedShadowNodeList>(SharedShadowNodeList(*children));
|
||||||
|
SharedShadowNode rootShadowNode = componentDescriptor.cloneShadowNode(previousRootShadowNode, nullptr, childrenCopy);
|
||||||
|
|
||||||
|
SharedViewShadowNode viewShadowNode = std::dynamic_pointer_cast<const ViewShadowNode>(rootShadowNode);
|
||||||
|
LayoutContext layoutContext = LayoutContext();
|
||||||
|
layoutContext.affectedShadowNodes = std::make_shared<std::unordered_set<SharedLayoutableShadowNode>>();
|
||||||
|
|
||||||
|
auto nonConstViewShadowNode = std::const_pointer_cast<ViewShadowNode>(viewShadowNode);
|
||||||
|
nonConstViewShadowNode->layout(layoutContext);
|
||||||
|
|
||||||
|
rootShadowNode->sealRecursive();
|
||||||
|
|
||||||
|
printf("## layouted rootShadowNode: %s \n", nonConstViewShadowNode->getDebugDescription(0).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace react
|
||||||
|
} // namespace facebook
|
|
@ -7,18 +7,22 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <folly/dynamic.h>
|
|
||||||
#include <folly/FBVector.h>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include <folly/dynamic.h>
|
||||||
|
|
||||||
|
#include <fabric/core/ComponentDescriptor.h>
|
||||||
#include <fabric/core/ShadowNode.h>
|
#include <fabric/core/ShadowNode.h>
|
||||||
|
#include <fabric/uimanager/ComponentDescriptorRegistry.h>
|
||||||
|
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
namespace react {
|
namespace react {
|
||||||
|
|
||||||
class IFabricPlatformUIOperationManager;
|
class IFabricPlatformUIOperationManager;
|
||||||
|
class ComponentDescriptorRegistry;
|
||||||
|
|
||||||
class FabricUIManager {
|
class FabricUIManager {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FabricUIManager(const std::shared_ptr<IFabricPlatformUIOperationManager> &platformUIOperationManager);
|
FabricUIManager(const std::shared_ptr<IFabricPlatformUIOperationManager> &platformUIOperationManager);
|
||||||
|
|
||||||
|
@ -33,6 +37,7 @@ public:
|
||||||
void completeRoot(int rootTag, const SharedShadowNodeUnsharedList &childSet);
|
void completeRoot(int rootTag, const SharedShadowNodeUnsharedList &childSet);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
ComponentDescriptorRegistry _registry;
|
||||||
std::shared_ptr<IFabricPlatformUIOperationManager> platformUIOperationManager_;
|
std::shared_ptr<IFabricPlatformUIOperationManager> platformUIOperationManager_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue