conversions.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <folly/dynamic.h>
  9. #include <react/components/scrollview/primitives.h>
  10. namespace facebook {
  11. namespace react {
  12. inline void fromRawValue(
  13. const RawValue &value,
  14. ScrollViewSnapToAlignment &result) {
  15. auto string = (std::string)value;
  16. if (string == "start") {
  17. result = ScrollViewSnapToAlignment::Start;
  18. return;
  19. }
  20. if (string == "center") {
  21. result = ScrollViewSnapToAlignment::Center;
  22. return;
  23. }
  24. if (string == "end") {
  25. result = ScrollViewSnapToAlignment::End;
  26. return;
  27. }
  28. abort();
  29. }
  30. inline void fromRawValue(
  31. const RawValue &value,
  32. ScrollViewIndicatorStyle &result) {
  33. auto string = (std::string)value;
  34. if (string == "default") {
  35. result = ScrollViewIndicatorStyle::Default;
  36. return;
  37. }
  38. if (string == "black") {
  39. result = ScrollViewIndicatorStyle::Black;
  40. return;
  41. }
  42. if (string == "white") {
  43. result = ScrollViewIndicatorStyle::White;
  44. return;
  45. }
  46. abort();
  47. }
  48. inline void fromRawValue(
  49. const RawValue &value,
  50. ScrollViewKeyboardDismissMode &result) {
  51. auto string = (std::string)value;
  52. if (string == "none") {
  53. result = ScrollViewKeyboardDismissMode::None;
  54. return;
  55. }
  56. if (string == "on-drag") {
  57. result = ScrollViewKeyboardDismissMode::OnDrag;
  58. return;
  59. }
  60. if (string == "interactive") {
  61. result = ScrollViewKeyboardDismissMode::Interactive;
  62. return;
  63. }
  64. abort();
  65. }
  66. inline std::string toString(const ScrollViewSnapToAlignment &value) {
  67. switch (value) {
  68. case ScrollViewSnapToAlignment::Start:
  69. return "start";
  70. case ScrollViewSnapToAlignment::Center:
  71. return "center";
  72. case ScrollViewSnapToAlignment::End:
  73. return "end";
  74. }
  75. }
  76. inline std::string toString(const ScrollViewIndicatorStyle &value) {
  77. switch (value) {
  78. case ScrollViewIndicatorStyle::Default:
  79. return "default";
  80. case ScrollViewIndicatorStyle::Black:
  81. return "black";
  82. case ScrollViewIndicatorStyle::White:
  83. return "white";
  84. }
  85. }
  86. inline std::string toString(const ScrollViewKeyboardDismissMode &value) {
  87. switch (value) {
  88. case ScrollViewKeyboardDismissMode::None:
  89. return "none";
  90. case ScrollViewKeyboardDismissMode::OnDrag:
  91. return "on-drag";
  92. case ScrollViewKeyboardDismissMode::Interactive:
  93. return "interactive";
  94. }
  95. }
  96. } // namespace react
  97. } // namespace facebook