react-native/ReactCommon/fabric/uimanager/UITemplateProcessor.h
Spencer Ahrens ac9e09d079 rename ReactBytecode -> UITemplate
Summary: React bytecode is kind of a different thing that sebmarkbage already has in mind so lets keep the namespace separate.

Reviewed By: mdvacca

Differential Revision: D12896293

fbshipit-source-id: e0f266da6e7a051bcf5defea49b958452342754d
2018-11-05 15:43:55 -08:00

64 lines
1.7 KiB
C++

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <memory>
#include <folly/dynamic.h>
#include <fabric/core/ShadowNode.h>
#include <fabric/uimanager/ComponentDescriptorRegistry.h>
#include <fabric/uimanager/UIManagerDelegate.h>
namespace facebook {
namespace react {
// Temporary NativeModuleRegistry definition
using NativeModuleCallFn =
std::function<folly::dynamic(const std::string &, const folly::dynamic &)>;
class NativeModuleRegistry {
public:
void registerModule(
const std::string &moduleName,
NativeModuleCallFn callFn) {
modules_.emplace(moduleName, callFn);
}
folly::dynamic call(
const std::string &moduleName,
const std::string &methodName,
const folly::dynamic &args) const {
return modules_.at(moduleName)(methodName, args);
}
private:
std::unordered_map<std::string, NativeModuleCallFn> modules_;
};
class UITemplateProcessor {
public:
static SharedShadowNode buildShadowTree(
const std::string &jsonStr,
int rootTag,
const folly::dynamic &params,
const ComponentDescriptorRegistry &componentDescriptorRegistry,
const NativeModuleRegistry &nativeModuleRegistry);
private:
static SharedShadowNode runCommand(
const folly::dynamic &command,
Tag rootTag,
std::vector<SharedShadowNode> &nodes,
std::vector<folly::dynamic> &registers,
const ComponentDescriptorRegistry &componentDescriptorRegistry,
const NativeModuleRegistry &nativeModuleRegistry);
};
} // namespace react
} // namespace facebook