StubView.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 "StubView.h"
  8. namespace facebook {
  9. namespace react {
  10. void StubView::update(ShadowView const &shadowView) {
  11. componentName = shadowView.componentName;
  12. componentHandle = shadowView.componentHandle;
  13. tag = shadowView.tag;
  14. props = shadowView.props;
  15. eventEmitter = shadowView.eventEmitter;
  16. layoutMetrics = shadowView.layoutMetrics;
  17. state = shadowView.state;
  18. }
  19. bool operator==(StubView const &lhs, StubView const &rhs) {
  20. return std::tie(lhs.props, lhs.layoutMetrics) ==
  21. std::tie(rhs.props, rhs.layoutMetrics);
  22. }
  23. bool operator!=(StubView const &lhs, StubView const &rhs) {
  24. return !(lhs == rhs);
  25. }
  26. #if RN_DEBUG_STRING_CONVERTIBLE
  27. std::string getDebugName(StubView const &stubView) {
  28. return std::string{"Stub"} +
  29. std::string{stubView.componentHandle ? stubView.componentName
  30. : "[invalid]"};
  31. }
  32. std::vector<DebugStringConvertibleObject> getDebugProps(
  33. StubView const &stubView,
  34. DebugStringConvertibleOptions options) {
  35. return {
  36. {"tag", getDebugDescription(stubView.tag, options)},
  37. {"props", getDebugDescription(stubView.props, options)},
  38. {"eventEmitter", getDebugDescription(stubView.eventEmitter, options)},
  39. {"layoutMetrics", getDebugDescription(stubView.layoutMetrics, options)},
  40. {"state", getDebugDescription(stubView.state, options)},
  41. };
  42. }
  43. std::vector<StubView> getDebugChildren(
  44. StubView const &stubView,
  45. DebugStringConvertibleOptions options) {
  46. std::vector<StubView> result;
  47. for (auto const &child : stubView.children) {
  48. result.push_back(*child);
  49. }
  50. return result;
  51. }
  52. #endif
  53. } // namespace react
  54. } // namespace facebook