feat(gestures): add locationX and locationY to double tap event data

This commit is contained in:
lukecurran
2020-02-13 14:57:56 -06:00
parent dd11158374
commit 5ff78e2ad2
3 changed files with 43 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
// Definitions.
import { GestureEventData, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, GestureEventDataWithState } from ".";
import { DoubleTapGestureEventData, GestureEventData, GestureEventDataWithState, PanGestureEventData, RotationGestureEventData, SwipeGestureEventData } from ".";
import { View, EventData } from "../core/view";
// Types.
@@ -89,7 +89,7 @@ function initializeTapAndDoubleTapGestureListener() {
timer.clearTimeout(this._tapTimeoutId);
}
if (this._type & GestureTypes.doubleTap) {
const args = _getArgs(GestureTypes.doubleTap, this._target, motionEvent);
const args = _getDoubleTapArgs(this._target, motionEvent);
_executeCallback(this._observer, args);
}
}
@@ -395,6 +395,19 @@ function _getLongPressArgs(type: GestureTypes, view: View, state: GestureStateTy
};
}
function _getDoubleTapArgs(view: View, e: android.view.MotionEvent): DoubleTapGestureEventData {
return <DoubleTapGestureEventData>{
type: GestureTypes.doubleTap,
view: view,
android: e,
locationX: e.getX() / layout.getDisplayDensity(),
locationY: e.getY() / layout.getDisplayDensity(),
ios: undefined,
object: view,
eventName: toString(GestureTypes.doubleTap),
};
}
function _getSwipeArgs(direction: SwipeDirection, view: View,
initialEvent: android.view.MotionEvent, currentEvent: android.view.MotionEvent): SwipeGestureEventData {
return <SwipeGestureEventData>{

View File

@@ -212,6 +212,14 @@ export interface PinchGestureEventData extends GestureEventDataWithState {
getFocusY(): number;
}
/**
* Provides gesture event data for double tap gesture.
*/
export interface DoubleTapGestureEventData extends GestureEventData {
locationX: number;
locationY: number;
}
/**
* Provides gesture event data for swipe gesture.
*/

View File

@@ -1,5 +1,5 @@
// Definitions.
import { GestureEventData, GestureEventDataWithState, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, PinchGestureEventData } from ".";
import { DoubleTapGestureEventData, GestureEventData, GestureEventDataWithState, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, PinchGestureEventData } from ".";
import { View, EventData } from "../core/view";
// Types.
@@ -127,7 +127,9 @@ export class GesturesObserver extends GesturesObserverBase {
}
if (type & GestureTypes.doubleTap) {
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.doubleTap));
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.doubleTap, args => {
this._executeCallback(_getDoubleTapData(args));
}));
}
if (type & GestureTypes.pinch) {
@@ -298,6 +300,22 @@ function _getSwipeDirection(direction: UISwipeGestureRecognizerDirection): Swipe
}
}
function _getDoubleTapData(args: GestureEventData): DoubleTapGestureEventData {
const recognizer = <UITapGestureRecognizer>args.ios;
const location: CGPoint = recognizer.locationInView(args.view.nativeViewProtected);
return <DoubleTapGestureEventData>{
type: args.type,
view: args.view,
ios: args.ios,
android: undefined,
locationX: location.x,
locationY: location.y,
object: args.view,
eventName: toString(args.type)
};
}
function _getPinchData(args: GestureEventData): PinchGestureEventData {
const recognizer = <UIPinchGestureRecognizer>args.ios;
const center = recognizer.locationInView(args.view.nativeViewProtected);