UITemplateProcessor.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #pragma once
  8. #include <memory>
  9. #include <folly/dynamic.h>
  10. #include <react/config/ReactNativeConfig.h>
  11. #include <react/core/ShadowNode.h>
  12. #include <react/uimanager/ComponentDescriptorRegistry.h>
  13. #include <react/uimanager/UIManagerDelegate.h>
  14. namespace facebook {
  15. namespace react {
  16. // Temporary NativeModuleRegistry definition
  17. using NativeModuleCallFn =
  18. std::function<folly::dynamic(const std::string &, const folly::dynamic &)>;
  19. class NativeModuleRegistry {
  20. public:
  21. void registerModule(
  22. const std::string &moduleName,
  23. NativeModuleCallFn callFn) {
  24. modules_.emplace(moduleName, callFn);
  25. }
  26. folly::dynamic call(
  27. const std::string &moduleName,
  28. const std::string &methodName,
  29. const folly::dynamic &args) const {
  30. return modules_.at(moduleName)(methodName, args);
  31. }
  32. private:
  33. std::unordered_map<std::string, NativeModuleCallFn> modules_;
  34. };
  35. class UITemplateProcessor {
  36. public:
  37. static ShadowNode::Shared buildShadowTree(
  38. const std::string &jsonStr,
  39. int rootTag,
  40. const folly::dynamic &params,
  41. const ComponentDescriptorRegistry &componentDescriptorRegistry,
  42. const NativeModuleRegistry &nativeModuleRegistry,
  43. const std::shared_ptr<const ReactNativeConfig> reactNativeConfig);
  44. private:
  45. static ShadowNode::Shared runCommand(
  46. const folly::dynamic &command,
  47. Tag rootTag,
  48. std::vector<SharedShadowNode> &nodes,
  49. std::vector<folly::dynamic> &registers,
  50. const ComponentDescriptorRegistry &componentDescriptorRegistry,
  51. const NativeModuleRegistry &nativeModuleRegistry,
  52. const std::shared_ptr<const ReactNativeConfig> reactNativeConfig);
  53. };
  54. } // namespace react
  55. } // namespace facebook