ShadowView.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include "ShadowView.h"
  8. #include <react/core/LayoutableShadowNode.h>
  9. namespace facebook {
  10. namespace react {
  11. static LayoutMetrics layoutMetricsFromShadowNode(ShadowNode const &shadowNode) {
  12. auto layotableShadowNode =
  13. traitCast<LayoutableShadowNode const *>(&shadowNode);
  14. return layotableShadowNode ? layotableShadowNode->getLayoutMetrics()
  15. : EmptyLayoutMetrics;
  16. }
  17. ShadowView::ShadowView(const ShadowNode &shadowNode)
  18. : componentName(shadowNode.getComponentName()),
  19. componentHandle(shadowNode.getComponentHandle()),
  20. tag(shadowNode.getTag()),
  21. props(shadowNode.getProps()),
  22. eventEmitter(shadowNode.getEventEmitter()),
  23. layoutMetrics(layoutMetricsFromShadowNode(shadowNode)),
  24. state(shadowNode.getState()) {}
  25. bool ShadowView::operator==(const ShadowView &rhs) const {
  26. return std::tie(
  27. this->tag,
  28. this->componentName,
  29. this->props,
  30. this->eventEmitter,
  31. this->layoutMetrics,
  32. this->state) ==
  33. std::tie(
  34. rhs.tag,
  35. rhs.componentName,
  36. rhs.props,
  37. rhs.eventEmitter,
  38. rhs.layoutMetrics,
  39. rhs.state);
  40. }
  41. bool ShadowView::operator!=(const ShadowView &rhs) const {
  42. return !(*this == rhs);
  43. }
  44. #if RN_DEBUG_STRING_CONVERTIBLE
  45. std::string getDebugName(ShadowView const &object) {
  46. return object.componentHandle == 0 ? "Invalid" : object.componentName;
  47. }
  48. std::vector<DebugStringConvertibleObject> getDebugProps(
  49. ShadowView const &object,
  50. DebugStringConvertibleOptions options) {
  51. return {
  52. {"tag", getDebugDescription(object.tag, options)},
  53. {"props", getDebugDescription(object.props, options)},
  54. {"eventEmitter", getDebugDescription(object.eventEmitter, options)},
  55. {"layoutMetrics", getDebugDescription(object.layoutMetrics, options)},
  56. {"state", getDebugDescription(object.state, options)},
  57. };
  58. }
  59. #endif
  60. bool ShadowViewNodePair::operator==(const ShadowViewNodePair &rhs) const {
  61. return this->shadowNode == rhs.shadowNode;
  62. }
  63. bool ShadowViewNodePair::operator!=(const ShadowViewNodePair &rhs) const {
  64. return !(*this == rhs);
  65. }
  66. } // namespace react
  67. } // namespace facebook