Touch.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 <react/core/ReactPrimitives.h>
  9. #include <react/debug/DebugStringConvertible.h>
  10. #include <react/graphics/Geometry.h>
  11. namespace facebook {
  12. namespace react {
  13. /*
  14. * Describes an individual touch point for a touch event.
  15. * See https://www.w3.org/TR/touch-events/ for more details.
  16. */
  17. struct Touch {
  18. /*
  19. * The coordinate of point relative to the root component in points.
  20. */
  21. Point pagePoint;
  22. /*
  23. * The coordinate of point relative to the target component in points.
  24. */
  25. Point offsetPoint;
  26. /*
  27. * The coordinate of point relative to the screen component in points.
  28. */
  29. Point screenPoint;
  30. /*
  31. * An identification number for each touch point.
  32. */
  33. int identifier;
  34. /*
  35. * The tag of a component on which the touch point started when it was first
  36. * placed on the surface, even if the touch point has since moved outside the
  37. * interactive area of that element.
  38. */
  39. Tag target;
  40. /*
  41. * The force of the touch.
  42. */
  43. Float force;
  44. /*
  45. * The time in seconds when the touch occurred or when it was last mutated.
  46. */
  47. Float timestamp;
  48. /*
  49. * The particular implementation of `Hasher` and (especially) `Comparator`
  50. * make sense only when `Touch` object is used as a *key* in indexed
  51. * collections. Because of that they are expressed as separate classes.
  52. */
  53. struct Hasher {
  54. size_t operator()(Touch const &touch) const {
  55. return std::hash<decltype(touch.identifier)>()(touch.identifier);
  56. }
  57. };
  58. struct Comparator {
  59. bool operator()(Touch const &lhs, Touch const &rhs) const {
  60. return lhs.identifier == rhs.identifier;
  61. }
  62. };
  63. };
  64. using Touches = std::unordered_set<Touch, Touch::Hasher, Touch::Comparator>;
  65. #if RN_DEBUG_STRING_CONVERTIBLE
  66. std::string getDebugName(Touch const &touch);
  67. std::vector<DebugStringConvertibleObject> getDebugProps(
  68. Touch const &object,
  69. DebugStringConvertibleOptions options);
  70. #endif
  71. } // namespace react
  72. } // namespace facebook