Files
react-native/ReactCommon/react/renderer/components/view/PointerEvent.cpp
T
Vincent Riemer 546c4b4c6c Add isPrimary property implementation to the PointerEvent object
Summary:
Changelog: [iOS][Internal] - Add isPrimary property implementation to the PointerEvent object

This diff adds the `isPrimary` property to the PointerEvent object iOS implementation. In addition this adds a related change where we "reserve" the 0 touch identifier for mouse events and the 1 identifier for apple pencil events. This is an easy way to ensure that these pointers are always consistent no matter what happens. Since mouse & pencil pointers should always be considered the primary pointer, that allows us to focus the more advanced primary pointer differentiation purely on touch events.

The logic for this touch event primary pointer differentiation is essentially setting the first touch it recieves as a primary pointer, setting it on touch registration, and sets all subsequent touchs (while the first touch is down) as not the primary pointers. When that primary pointer is lifted, the class property keeping track of the primary pointer is reset and then the **next** pointer (secondary pointers which had already started before the previous primary pointer was lifted are not "upgraded" to primary) is marked as primary. A new platform test is also included in this diff in order to verify the aforementioned behavior.

Reviewed By: lunaleaps

Differential Revision: D37961707

fbshipit-source-id: ae8b78c5bfea6902fb73094fca1552e4e648ea44
2022-07-26 11:41:48 -07:00

50 lines
1.9 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "PointerEvent.h"
namespace facebook {
namespace react {
#if RN_DEBUG_STRING_CONVERTIBLE
std::string getDebugName(PointerEvent const &pointerEvent) {
return "PointerEvent";
}
std::vector<DebugStringConvertibleObject> getDebugProps(
PointerEvent const &pointerEvent,
DebugStringConvertibleOptions options) {
return {
{"pointerId", getDebugDescription(pointerEvent.pointerId, options)},
{"pressure", getDebugDescription(pointerEvent.pressure, options)},
{"pointerType", getDebugDescription(pointerEvent.pointerType, options)},
{"clientPoint", getDebugDescription(pointerEvent.clientPoint, options)},
{"screenPoint", getDebugDescription(pointerEvent.screenPoint, options)},
{"offsetPoint", getDebugDescription(pointerEvent.offsetPoint, options)},
{"width", getDebugDescription(pointerEvent.width, options)},
{"height", getDebugDescription(pointerEvent.height, options)},
{"tiltX", getDebugDescription(pointerEvent.tiltX, options)},
{"tiltY", getDebugDescription(pointerEvent.tiltY, options)},
{"detail", getDebugDescription(pointerEvent.detail, options)},
{"buttons", getDebugDescription(pointerEvent.buttons, options)},
{"tangentialPressure",
getDebugDescription(pointerEvent.tangentialPressure, options)},
{"twist", getDebugDescription(pointerEvent.twist, options)},
{"ctrlKey", getDebugDescription(pointerEvent.ctrlKey, options)},
{"shiftKey", getDebugDescription(pointerEvent.shiftKey, options)},
{"altKey", getDebugDescription(pointerEvent.altKey, options)},
{"metaKey", getDebugDescription(pointerEvent.metaKey, options)},
{"isPrimary", getDebugDescription(pointerEvent.isPrimary, options)},
};
}
#endif
} // namespace react
} // namespace facebook