ShadowViewMutation.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <vector>
  9. #include <react/mounting/ShadowView.h>
  10. namespace facebook {
  11. namespace react {
  12. /*
  13. * Describes a single native view tree mutation which may contain
  14. * pointers to an old shadow view, a new shadow view, a parent shadow view and
  15. * final index of inserted or updated view.
  16. * Use static methods to instantiate mutations of different types.
  17. */
  18. struct ShadowViewMutation final {
  19. using List = std::vector<ShadowViewMutation>;
  20. #pragma mark - Designated Initializers
  21. /*
  22. * Creates and returns an `Create` mutation.
  23. */
  24. static ShadowViewMutation CreateMutation(ShadowView shadowView);
  25. /*
  26. * Creates and returns an `Delete` mutation.
  27. */
  28. static ShadowViewMutation DeleteMutation(ShadowView shadowView);
  29. /*
  30. * Creates and returns an `Insert` mutation.
  31. */
  32. static ShadowViewMutation InsertMutation(
  33. ShadowView parentShadowView,
  34. ShadowView childShadowView,
  35. int index);
  36. /*
  37. * Creates and returns a `Remove` mutation.
  38. */
  39. static ShadowViewMutation RemoveMutation(
  40. ShadowView parentShadowView,
  41. ShadowView childShadowView,
  42. int index);
  43. /*
  44. * Creates and returns an `Update` mutation.
  45. */
  46. static ShadowViewMutation UpdateMutation(
  47. ShadowView parentShadowView,
  48. ShadowView oldChildShadowView,
  49. ShadowView newChildShadowView,
  50. int index);
  51. #pragma mark - Type
  52. enum Type { Create, Delete, Insert, Remove, Update };
  53. #pragma mark - Fields
  54. Type type = {Create};
  55. ShadowView parentShadowView = {};
  56. ShadowView oldChildShadowView = {};
  57. ShadowView newChildShadowView = {};
  58. int index = {};
  59. };
  60. using ShadowViewMutationList = std::vector<ShadowViewMutation>;
  61. #if RN_DEBUG_STRING_CONVERTIBLE
  62. std::string getDebugName(ShadowViewMutation const &object);
  63. std::vector<DebugStringConvertibleObject> getDebugProps(
  64. ShadowViewMutation const &object,
  65. DebugStringConvertibleOptions options);
  66. #endif
  67. } // namespace react
  68. } // namespace facebook