ShadowViewMutation.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 "ShadowViewMutation.h"
  8. namespace facebook {
  9. namespace react {
  10. ShadowViewMutation ShadowViewMutation::CreateMutation(ShadowView shadowView) {
  11. return {
  12. /* .type = */ Create,
  13. /* .parentShadowView = */ {},
  14. /* .oldChildShadowView = */ {},
  15. /* .newChildShadowView = */ shadowView,
  16. /* .index = */ -1,
  17. };
  18. }
  19. ShadowViewMutation ShadowViewMutation::DeleteMutation(ShadowView shadowView) {
  20. return {
  21. /* .type = */ Delete,
  22. /* .parentShadowView = */ {},
  23. /* .oldChildShadowView = */ shadowView,
  24. /* .newChildShadowView = */ {},
  25. /* .index = */ -1,
  26. };
  27. }
  28. ShadowViewMutation ShadowViewMutation::InsertMutation(
  29. ShadowView parentShadowView,
  30. ShadowView childShadowView,
  31. int index) {
  32. return {
  33. /* .type = */ Insert,
  34. /* .parentShadowView = */ parentShadowView,
  35. /* .oldChildShadowView = */ {},
  36. /* .newChildShadowView = */ childShadowView,
  37. /* .index = */ index,
  38. };
  39. }
  40. ShadowViewMutation ShadowViewMutation::RemoveMutation(
  41. ShadowView parentShadowView,
  42. ShadowView childShadowView,
  43. int index) {
  44. return {
  45. /* .type = */ Remove,
  46. /* .parentShadowView = */ parentShadowView,
  47. /* .oldChildShadowView = */ childShadowView,
  48. /* .newChildShadowView = */ {},
  49. /* .index = */ index,
  50. };
  51. }
  52. ShadowViewMutation ShadowViewMutation::UpdateMutation(
  53. ShadowView parentShadowView,
  54. ShadowView oldChildShadowView,
  55. ShadowView newChildShadowView,
  56. int index) {
  57. return {
  58. /* .type = */ Update,
  59. /* .parentShadowView = */ parentShadowView,
  60. /* .oldChildShadowView = */ oldChildShadowView,
  61. /* .newChildShadowView = */ newChildShadowView,
  62. /* .index = */ index,
  63. };
  64. }
  65. #if RN_DEBUG_STRING_CONVERTIBLE
  66. std::string getDebugName(ShadowViewMutation const &mutation) {
  67. switch (mutation.type) {
  68. case ShadowViewMutation::Create:
  69. return "Create";
  70. case ShadowViewMutation::Delete:
  71. return "Delete";
  72. case ShadowViewMutation::Insert:
  73. return "Insert";
  74. case ShadowViewMutation::Remove:
  75. return "Remove";
  76. case ShadowViewMutation::Update:
  77. return "Update";
  78. }
  79. }
  80. std::vector<DebugStringConvertibleObject> getDebugProps(
  81. ShadowViewMutation const &mutation,
  82. DebugStringConvertibleOptions options) {
  83. return {
  84. mutation.oldChildShadowView.componentHandle
  85. ? DebugStringConvertibleObject{"oldChild",
  86. getDebugDescription(
  87. mutation.oldChildShadowView,
  88. options)}
  89. : DebugStringConvertibleObject{},
  90. mutation.newChildShadowView.componentHandle
  91. ? DebugStringConvertibleObject{"newChild",
  92. getDebugDescription(
  93. mutation.newChildShadowView,
  94. options)}
  95. : DebugStringConvertibleObject{},
  96. mutation.parentShadowView.componentHandle
  97. ? DebugStringConvertibleObject{"parent",
  98. getDebugDescription(
  99. mutation.parentShadowView,
  100. options)}
  101. : DebugStringConvertibleObject{},
  102. mutation.index != -1
  103. ? DebugStringConvertibleObject{"index",
  104. getDebugDescription(
  105. mutation.index, options)}
  106. : DebugStringConvertibleObject{},
  107. };
  108. }
  109. #endif
  110. } // namespace react
  111. } // namespace facebook