ShadowView.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 <better/small_vector.h>
  9. #include <folly/Hash.h>
  10. #include <react/core/EventEmitter.h>
  11. #include <react/core/LayoutMetrics.h>
  12. #include <react/core/Props.h>
  13. #include <react/core/ReactPrimitives.h>
  14. #include <react/core/ShadowNode.h>
  15. namespace facebook {
  16. namespace react {
  17. /*
  18. * Describes a view that can be mounted.
  19. */
  20. struct ShadowView final {
  21. ShadowView() = default;
  22. ShadowView(ShadowView const &shadowView) = default;
  23. ShadowView(ShadowView &&shadowView) noexcept = default;
  24. /*
  25. * Constructs a `ShadowView` from given `ShadowNode`.
  26. */
  27. explicit ShadowView(ShadowNode const &shadowNode);
  28. ShadowView &operator=(ShadowView const &other) = default;
  29. ShadowView &operator=(ShadowView &&other) = default;
  30. bool operator==(ShadowView const &rhs) const;
  31. bool operator!=(ShadowView const &rhs) const;
  32. ComponentName componentName{};
  33. ComponentHandle componentHandle{};
  34. Tag tag{};
  35. Props::Shared props{};
  36. EventEmitter::Shared eventEmitter{};
  37. LayoutMetrics layoutMetrics{EmptyLayoutMetrics};
  38. State::Shared state{};
  39. };
  40. #if RN_DEBUG_STRING_CONVERTIBLE
  41. std::string getDebugName(ShadowView const &object);
  42. std::vector<DebugStringConvertibleObject> getDebugProps(
  43. ShadowView const &object,
  44. DebugStringConvertibleOptions options);
  45. #endif
  46. /*
  47. * Describes pair of a `ShadowView` and a `ShadowNode`.
  48. */
  49. struct ShadowViewNodePair final {
  50. using List = better::
  51. small_vector<ShadowViewNodePair, kShadowNodeChildrenSmallVectorSize>;
  52. ShadowView shadowView;
  53. ShadowNode const *shadowNode;
  54. /*
  55. * The stored pointer to `ShadowNode` represents an indentity of the pair.
  56. */
  57. bool operator==(const ShadowViewNodePair &rhs) const;
  58. bool operator!=(const ShadowViewNodePair &rhs) const;
  59. };
  60. } // namespace react
  61. } // namespace facebook
  62. namespace std {
  63. template <>
  64. struct hash<facebook::react::ShadowView> {
  65. size_t operator()(const facebook::react::ShadowView &shadowView) const {
  66. return folly::hash::hash_combine(
  67. 0,
  68. shadowView.componentHandle,
  69. shadowView.tag,
  70. shadowView.props,
  71. shadowView.eventEmitter,
  72. shadowView.state);
  73. }
  74. };
  75. } // namespace std