ConcreteViewShadowNode.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <react/components/view/ViewEventEmitter.h>
  9. #include <react/components/view/ViewProps.h>
  10. #include <react/components/view/YogaLayoutableShadowNode.h>
  11. #include <react/core/ConcreteShadowNode.h>
  12. #include <react/core/LayoutableShadowNode.h>
  13. #include <react/core/ShadowNode.h>
  14. #include <react/core/ShadowNodeFragment.h>
  15. #include <react/debug/DebugStringConvertibleItem.h>
  16. namespace facebook {
  17. namespace react {
  18. /*
  19. * Template for all <View>-like classes (classes which have all same props
  20. * as <View> and similar basic behaviour).
  21. * For example: <Paragraph>, <Image>, but not <Text>, <RawText>.
  22. */
  23. template <
  24. const char *concreteComponentName,
  25. typename ViewPropsT = ViewProps,
  26. typename ViewEventEmitterT = ViewEventEmitter,
  27. typename... Ts>
  28. class ConcreteViewShadowNode : public ConcreteShadowNode<
  29. concreteComponentName,
  30. YogaLayoutableShadowNode,
  31. ViewPropsT,
  32. ViewEventEmitterT,
  33. Ts...> {
  34. static_assert(
  35. std::is_base_of<ViewProps, ViewPropsT>::value,
  36. "ViewPropsT must be a descendant of ViewProps");
  37. static_assert(
  38. std::is_base_of<YogaStylableProps, ViewPropsT>::value,
  39. "ViewPropsT must be a descendant of YogaStylableProps");
  40. static_assert(
  41. std::is_base_of<AccessibilityProps, ViewPropsT>::value,
  42. "ViewPropsT must be a descendant of AccessibilityProps");
  43. public:
  44. using BaseShadowNode = ConcreteShadowNode<
  45. concreteComponentName,
  46. YogaLayoutableShadowNode,
  47. ViewPropsT,
  48. ViewEventEmitterT,
  49. Ts...>;
  50. ConcreteViewShadowNode(
  51. ShadowNodeFragment const &fragment,
  52. ShadowNodeFamily::Shared const &family,
  53. ShadowNodeTraits traits)
  54. : BaseShadowNode(fragment, family, traits) {
  55. initialize();
  56. }
  57. ConcreteViewShadowNode(
  58. ShadowNode const &sourceShadowNode,
  59. ShadowNodeFragment const &fragment)
  60. : BaseShadowNode(sourceShadowNode, fragment) {
  61. initialize();
  62. }
  63. using ConcreteViewProps = ViewPropsT;
  64. using BaseShadowNode::BaseShadowNode;
  65. static ShadowNodeTraits BaseTraits() {
  66. auto traits = BaseShadowNode::BaseTraits();
  67. traits.set(ShadowNodeTraits::Trait::ViewKind);
  68. traits.set(ShadowNodeTraits::Trait::FormsStackingContext);
  69. traits.set(ShadowNodeTraits::Trait::FormsView);
  70. return traits;
  71. }
  72. Transform getTransform() const override {
  73. return BaseShadowNode::getConcreteProps().transform;
  74. }
  75. #pragma mark - DebugStringConvertible
  76. #if RN_DEBUG_STRING_CONVERTIBLE
  77. SharedDebugStringConvertibleList getDebugProps() const override {
  78. auto list = SharedDebugStringConvertibleList{};
  79. auto basePropsList = ShadowNode::getDebugProps();
  80. std::move(
  81. basePropsList.begin(), basePropsList.end(), std::back_inserter(list));
  82. list.push_back(std::make_shared<DebugStringConvertibleItem>(
  83. "layout", "", LayoutableShadowNode::getDebugProps()));
  84. return list;
  85. }
  86. #endif
  87. private:
  88. void initialize() noexcept {
  89. BaseShadowNode::orderIndex_ = BaseShadowNode::getConcreteProps().zIndex;
  90. }
  91. };
  92. } // namespace react
  93. } // namespace facebook