UIManager.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 <folly/Optional.h>
  9. #include <folly/dynamic.h>
  10. #include <jsi/jsi.h>
  11. #include <react/core/ShadowNode.h>
  12. #include <react/core/StateData.h>
  13. #include <react/mounting/ShadowTree.h>
  14. #include <react/mounting/ShadowTreeDelegate.h>
  15. #include <react/mounting/ShadowTreeRegistry.h>
  16. #include <react/uimanager/ComponentDescriptorRegistry.h>
  17. #include <react/uimanager/UIManagerDelegate.h>
  18. namespace facebook {
  19. namespace react {
  20. class UIManagerBinding;
  21. class UIManager final : public ShadowTreeDelegate {
  22. public:
  23. ~UIManager();
  24. void setComponentDescriptorRegistry(
  25. const SharedComponentDescriptorRegistry &componentDescriptorRegistry);
  26. /*
  27. * Sets and gets the UIManager's delegate.
  28. * The delegate is stored as a raw pointer, so the owner must null
  29. * the pointer before being destroyed.
  30. */
  31. void setDelegate(UIManagerDelegate *delegate);
  32. UIManagerDelegate *getDelegate();
  33. /*
  34. * Provides access to a UIManagerBindging.
  35. * The `callback` methods will not be called if the internal pointer to
  36. * `UIManagerBindging` is `nullptr`.
  37. * The callback is called synchronously on the same thread.
  38. */
  39. void visitBinding(
  40. std::function<void(UIManagerBinding const &uiManagerBinding)> callback)
  41. const;
  42. #pragma mark - ShadowTreeDelegate
  43. void shadowTreeDidFinishTransaction(
  44. ShadowTree const &shadowTree,
  45. MountingCoordinator::Shared const &mountingCoordinator) const override;
  46. private:
  47. friend class UIManagerBinding;
  48. friend class Scheduler;
  49. ShadowNode::Shared createNode(
  50. Tag tag,
  51. std::string const &componentName,
  52. SurfaceId surfaceId,
  53. const RawProps &props,
  54. SharedEventTarget eventTarget) const;
  55. ShadowNode::Shared cloneNode(
  56. const ShadowNode::Shared &shadowNode,
  57. const SharedShadowNodeSharedList &children = nullptr,
  58. const RawProps *rawProps = nullptr) const;
  59. void appendChild(
  60. const ShadowNode::Shared &parentShadowNode,
  61. const ShadowNode::Shared &childShadowNode) const;
  62. void completeSurface(
  63. SurfaceId surfaceId,
  64. const SharedShadowNodeUnsharedList &rootChildren) const;
  65. void setNativeProps(ShadowNode const &shadowNode, RawProps const &rawProps)
  66. const;
  67. void setJSResponder(
  68. const ShadowNode::Shared &shadowNode,
  69. const bool blockNativeResponder) const;
  70. void clearJSResponder() const;
  71. ShadowNode::Shared findNodeAtPoint(
  72. ShadowNode::Shared const &shadowNode,
  73. Point point) const;
  74. ShadowNode::Shared const *getNewestCloneOfShadowNode(
  75. ShadowNode::Shared const &shadowNode) const;
  76. /*
  77. * Returns layout metrics of given `shadowNode` relative to
  78. * `ancestorShadowNode` (relative to the root node in case if provided
  79. * `ancestorShadowNode` is nullptr).
  80. */
  81. LayoutMetrics getRelativeLayoutMetrics(
  82. ShadowNode const &shadowNode,
  83. ShadowNode const *ancestorShadowNode,
  84. LayoutableShadowNode::LayoutInspectingPolicy policy) const;
  85. /*
  86. * Creates a new shadow node with given state data, clones what's necessary
  87. * and performs a commit.
  88. */
  89. void updateState(StateUpdate const &stateUpdate) const;
  90. void dispatchCommand(
  91. const ShadowNode::Shared &shadowNode,
  92. std::string const &commandName,
  93. folly::dynamic const args) const;
  94. ShadowTreeRegistry const &getShadowTreeRegistry() const;
  95. SharedComponentDescriptorRegistry componentDescriptorRegistry_;
  96. UIManagerDelegate *delegate_;
  97. UIManagerBinding *uiManagerBinding_;
  98. ShadowTreeRegistry shadowTreeRegistry_{};
  99. };
  100. } // namespace react
  101. } // namespace facebook