Fabric: Touch and TouchEvent got own files and support for debug printing
Summary: That's essential for debugging touch events. Reviewed By: mdvacca Differential Revision: D15498192 fbshipit-source-id: 4a8e0a2b84a1935722518fdce03c10ba277f5702
This commit is contained in:
Родитель
6dbd809df5
Коммит
83f23982ca
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "Touch.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
#if RN_DEBUG_STRING_CONVERTIBLE
|
||||
|
||||
std::string getDebugName(Touch const &touch) {
|
||||
return "Touch";
|
||||
}
|
||||
|
||||
std::vector<DebugStringConvertibleObject> getDebugProps(
|
||||
Touch const &touch,
|
||||
DebugStringConvertibleOptions options) {
|
||||
return {
|
||||
{"pagePoint", getDebugDescription(touch.pagePoint, options)},
|
||||
{"offsetPoint", getDebugDescription(touch.offsetPoint, options)},
|
||||
{"screenPoint", getDebugDescription(touch.screenPoint, options)},
|
||||
{"identifier", getDebugDescription(touch.identifier, options)},
|
||||
{"target", getDebugDescription(touch.target, options)},
|
||||
{"force", getDebugDescription(touch.force, options)},
|
||||
{"timestamp", getDebugDescription(touch.timestamp, options)},
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <react/graphics/Geometry.h>
|
||||
#include <react/core/ReactPrimitives.h>
|
||||
#include <react/debug/DebugStringConvertible.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
/*
|
||||
* Describes an individual touch point for a touch event.
|
||||
* See https://www.w3.org/TR/touch-events/ for more details.
|
||||
*/
|
||||
struct Touch {
|
||||
/*
|
||||
* The coordinate of point relative to the root component in points.
|
||||
*/
|
||||
Point pagePoint;
|
||||
|
||||
/*
|
||||
* The coordinate of point relative to the target component in points.
|
||||
*/
|
||||
Point offsetPoint;
|
||||
|
||||
/*
|
||||
* The coordinate of point relative to the screen component in points.
|
||||
*/
|
||||
Point screenPoint;
|
||||
|
||||
/*
|
||||
* An identification number for each touch point.
|
||||
*/
|
||||
int identifier;
|
||||
|
||||
/*
|
||||
* The tag of a component on which the touch point started when it was first
|
||||
* placed on the surface, even if the touch point has since moved outside the
|
||||
* interactive area of that element.
|
||||
*/
|
||||
Tag target;
|
||||
|
||||
/*
|
||||
* The force of the touch.
|
||||
*/
|
||||
Float force;
|
||||
|
||||
/*
|
||||
* The time in seconds when the touch occurred or when it was last mutated.
|
||||
*/
|
||||
Float timestamp;
|
||||
|
||||
/*
|
||||
* The particular implementation of `Hasher` and (especially) `Comparator`
|
||||
* make sense only when `Touch` object is used as a *key* in indexed
|
||||
* collections. Because of that they are expressed as separate classes.
|
||||
*/
|
||||
struct Hasher {
|
||||
size_t operator()(Touch const &touch) const {
|
||||
return std::hash<decltype(touch.identifier)>()(touch.identifier);
|
||||
}
|
||||
};
|
||||
|
||||
struct Comparator {
|
||||
bool operator()(Touch const &lhs, Touch const &rhs) const {
|
||||
return lhs.identifier == rhs.identifier;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
using Touches = std::unordered_set<Touch, Touch::Hasher, Touch::Comparator>;
|
||||
|
||||
#if RN_DEBUG_STRING_CONVERTIBLE
|
||||
|
||||
std::string getDebugName(Touch const &touch);
|
||||
std::vector<DebugStringConvertibleObject> getDebugProps(
|
||||
Touch const &object,
|
||||
DebugStringConvertibleOptions options = {});
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "TouchEvent.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
#if RN_DEBUG_STRING_CONVERTIBLE
|
||||
|
||||
std::string getDebugName(TouchEvent const &touchEvent) {
|
||||
return "TouchEvent";
|
||||
}
|
||||
|
||||
std::vector<DebugStringConvertibleObject> getDebugProps(
|
||||
TouchEvent const &touchEvent,
|
||||
DebugStringConvertibleOptions options) {
|
||||
|
||||
return {
|
||||
{"touches", getDebugDescription(touchEvent.touches, options)},
|
||||
{"changedTouches", getDebugDescription(touchEvent.changedTouches, options)},
|
||||
{"targetTouches", getDebugDescription(touchEvent.targetTouches, options)},
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <react/debug/DebugStringConvertible.h>
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
#include <react/components/view/Touch.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
using Touches = std::unordered_set<Touch, Touch::Hasher, Touch::Comparator>;
|
||||
|
||||
/*
|
||||
* Defines the `touchstart`, `touchend`, `touchmove`, and `touchcancel` event
|
||||
* types.
|
||||
*/
|
||||
struct TouchEvent {
|
||||
/*
|
||||
* A list of Touches for every point of contact currently touching the
|
||||
* surface.
|
||||
*/
|
||||
Touches touches;
|
||||
|
||||
/*
|
||||
* A list of Touches for every point of contact which contributed to the
|
||||
* event.
|
||||
*/
|
||||
Touches changedTouches;
|
||||
|
||||
/*
|
||||
* A list of Touches for every point of contact that is touching the surface
|
||||
* and started on the element that is the target of the current event.
|
||||
*/
|
||||
Touches targetTouches;
|
||||
};
|
||||
|
||||
#if RN_DEBUG_STRING_CONVERTIBLE
|
||||
|
||||
std::string getDebugName(TouchEvent const &touchEvent);
|
||||
std::vector<DebugStringConvertibleObject> getDebugProps(
|
||||
TouchEvent const &touchEvent,
|
||||
DebugStringConvertibleOptions options = {});
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
|
@ -12,7 +12,7 @@ namespace react {
|
|||
|
||||
#pragma mark - Touches
|
||||
|
||||
static jsi::Value touchPayload(jsi::Runtime &runtime, const Touch &touch) {
|
||||
static jsi::Value touchPayload(jsi::Runtime &runtime, Touch const &touch) {
|
||||
auto object = jsi::Object(runtime);
|
||||
object.setProperty(runtime, "locationX", touch.offsetPoint.x);
|
||||
object.setProperty(runtime, "locationY", touch.offsetPoint.y);
|
||||
|
@ -29,10 +29,10 @@ static jsi::Value touchPayload(jsi::Runtime &runtime, const Touch &touch) {
|
|||
|
||||
static jsi::Value touchesPayload(
|
||||
jsi::Runtime &runtime,
|
||||
const Touches &touches) {
|
||||
Touches const &touches) {
|
||||
auto array = jsi::Array(runtime, touches.size());
|
||||
int i = 0;
|
||||
for (const auto &touch : touches) {
|
||||
for (auto const &touch : touches) {
|
||||
array.setValueAtIndex(runtime, i++, touchPayload(runtime, touch));
|
||||
}
|
||||
return array;
|
||||
|
@ -40,7 +40,7 @@ static jsi::Value touchesPayload(
|
|||
|
||||
static jsi::Value touchEventPayload(
|
||||
jsi::Runtime &runtime,
|
||||
const TouchEvent &event) {
|
||||
TouchEvent const &event) {
|
||||
auto object = jsi::Object(runtime);
|
||||
object.setProperty(
|
||||
runtime, "touches", touchesPayload(runtime, event.touches));
|
||||
|
@ -52,9 +52,9 @@ static jsi::Value touchEventPayload(
|
|||
}
|
||||
|
||||
void TouchEventEmitter::dispatchTouchEvent(
|
||||
const std::string &type,
|
||||
const TouchEvent &event,
|
||||
const EventPriority &priority) const {
|
||||
std::string const &type,
|
||||
TouchEvent const &event,
|
||||
EventPriority const &priority) const {
|
||||
dispatchEvent(
|
||||
type,
|
||||
[event](jsi::Runtime &runtime) {
|
||||
|
@ -63,19 +63,19 @@ void TouchEventEmitter::dispatchTouchEvent(
|
|||
priority);
|
||||
}
|
||||
|
||||
void TouchEventEmitter::onTouchStart(const TouchEvent &event) const {
|
||||
void TouchEventEmitter::onTouchStart(TouchEvent const &event) const {
|
||||
dispatchTouchEvent("touchStart", event, EventPriority::SynchronousUnbatched);
|
||||
}
|
||||
|
||||
void TouchEventEmitter::onTouchMove(const TouchEvent &event) const {
|
||||
void TouchEventEmitter::onTouchMove(TouchEvent const &event) const {
|
||||
dispatchTouchEvent("touchMove", event, EventPriority::SynchronousBatched);
|
||||
}
|
||||
|
||||
void TouchEventEmitter::onTouchEnd(const TouchEvent &event) const {
|
||||
void TouchEventEmitter::onTouchEnd(TouchEvent const &event) const {
|
||||
dispatchTouchEvent("touchEnd", event, EventPriority::SynchronousBatched);
|
||||
}
|
||||
|
||||
void TouchEventEmitter::onTouchCancel(const TouchEvent &event) const {
|
||||
void TouchEventEmitter::onTouchCancel(TouchEvent const &event) const {
|
||||
dispatchTouchEvent("touchCancel", event, EventPriority::SynchronousBatched);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,113 +9,30 @@
|
|||
#include <react/core/EventEmitter.h>
|
||||
#include <react/core/LayoutMetrics.h>
|
||||
#include <react/core/ReactPrimitives.h>
|
||||
#include <react/debug/DebugStringConvertible.h>
|
||||
#include <react/components/view/TouchEvent.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
/*
|
||||
* Describes an individual touch point for a touch event.
|
||||
* See https://www.w3.org/TR/touch-events/ for more details.
|
||||
*/
|
||||
struct Touch {
|
||||
/*
|
||||
* The coordinate of point relative to the root component in points.
|
||||
*/
|
||||
Point pagePoint;
|
||||
|
||||
/*
|
||||
* The coordinate of point relative to the target component in points.
|
||||
*/
|
||||
Point offsetPoint;
|
||||
|
||||
/*
|
||||
* The coordinate of point relative to the screen component in points.
|
||||
*/
|
||||
Point screenPoint;
|
||||
|
||||
/*
|
||||
* An identification number for each touch point.
|
||||
*/
|
||||
int identifier;
|
||||
|
||||
/*
|
||||
* The tag of a component on which the touch point started when it was first
|
||||
* placed on the surface, even if the touch point has since moved outside the
|
||||
* interactive area of that element.
|
||||
*/
|
||||
Tag target;
|
||||
|
||||
/*
|
||||
* The force of the touch.
|
||||
*/
|
||||
Float force;
|
||||
|
||||
/*
|
||||
* The time in seconds when the touch occurred or when it was last mutated.
|
||||
*/
|
||||
Float timestamp;
|
||||
|
||||
/*
|
||||
* The particular implementation of `Hasher` and (especially) `Comparator`
|
||||
* make sense only when `Touch` object is used as a *key* in indexed
|
||||
* collections. Because of that they are expressed as separate classes.
|
||||
*/
|
||||
struct Hasher {
|
||||
size_t operator()(const Touch &touch) const {
|
||||
return std::hash<decltype(touch.identifier)>()(touch.identifier);
|
||||
}
|
||||
};
|
||||
|
||||
struct Comparator {
|
||||
bool operator()(const Touch &lhs, const Touch &rhs) const {
|
||||
return lhs.identifier == rhs.identifier;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
using Touches = std::unordered_set<Touch, Touch::Hasher, Touch::Comparator>;
|
||||
|
||||
/*
|
||||
* Defines the `touchstart`, `touchend`, `touchmove`, and `touchcancel` event
|
||||
* types.
|
||||
*/
|
||||
struct TouchEvent {
|
||||
/*
|
||||
* A list of Touches for every point of contact currently touching the
|
||||
* surface.
|
||||
*/
|
||||
Touches touches;
|
||||
|
||||
/*
|
||||
* A list of Touches for every point of contact which contributed to the
|
||||
* event.
|
||||
*/
|
||||
Touches changedTouches;
|
||||
|
||||
/*
|
||||
* A list of Touches for every point of contact that is touching the surface
|
||||
* and started on the element that is the target of the current event.
|
||||
*/
|
||||
Touches targetTouches;
|
||||
};
|
||||
|
||||
class TouchEventEmitter;
|
||||
using SharedTouchEventEmitter = std::shared_ptr<const TouchEventEmitter>;
|
||||
|
||||
using SharedTouchEventEmitter = std::shared_ptr<TouchEventEmitter const>;
|
||||
|
||||
class TouchEventEmitter : public EventEmitter {
|
||||
public:
|
||||
using EventEmitter::EventEmitter;
|
||||
|
||||
void onTouchStart(const TouchEvent &event) const;
|
||||
void onTouchMove(const TouchEvent &event) const;
|
||||
void onTouchEnd(const TouchEvent &event) const;
|
||||
void onTouchCancel(const TouchEvent &event) const;
|
||||
void onTouchStart(TouchEvent const &event) const;
|
||||
void onTouchMove(TouchEvent const &event) const;
|
||||
void onTouchEnd(TouchEvent const &event) const;
|
||||
void onTouchCancel(TouchEvent const &event) const;
|
||||
|
||||
private:
|
||||
void dispatchTouchEvent(
|
||||
const std::string &type,
|
||||
const TouchEvent &event,
|
||||
const EventPriority &priority) const;
|
||||
std::string const &type,
|
||||
TouchEvent const &event,
|
||||
EventPriority const &priority) const;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <react/core/LayoutMetrics.h>
|
||||
#include <react/core/ReactPrimitives.h>
|
||||
|
||||
#include "TouchEventEmitter.h"
|
||||
|
||||
namespace facebook {
|
||||
|
|
Загрузка…
Ссылка в новой задаче