diff --git a/nativescript-core/ui/gestures/gestures.android.ts b/nativescript-core/ui/gestures/gestures.android.ts index 3b3de4bc3..d90171f0d 100644 --- a/nativescript-core/ui/gestures/gestures.android.ts +++ b/nativescript-core/ui/gestures/gestures.android.ts @@ -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 { + type: GestureTypes.doubleTap, + view: view, + android: e, + getX: () => e.getX() / layout.getDisplayDensity(), + getY: () => 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 { diff --git a/nativescript-core/ui/gestures/gestures.d.ts b/nativescript-core/ui/gestures/gestures.d.ts index 886cc2ad8..7c66d18ff 100644 --- a/nativescript-core/ui/gestures/gestures.d.ts +++ b/nativescript-core/ui/gestures/gestures.d.ts @@ -212,6 +212,14 @@ export interface PinchGestureEventData extends GestureEventDataWithState { getFocusY(): number; } +/** + * Provides gesture event data for double tap gesture. + */ +export interface DoubleTapGestureEventData extends GestureEventData { + getX(): number; + getY(): number; +} + /** * Provides gesture event data for swipe gesture. */ diff --git a/nativescript-core/ui/gestures/gestures.ios.ts b/nativescript-core/ui/gestures/gestures.ios.ts index d687b9092..2f36f938f 100644 --- a/nativescript-core/ui/gestures/gestures.ios.ts +++ b/nativescript-core/ui/gestures/gestures.ios.ts @@ -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 = args.ios; + const location: CGPoint = recognizer.locationInView(args.view.nativeViewProtected); + + return { + type: args.type, + view: args.view, + ios: args.ios, + android: undefined, + getX: () => location.x, + getY: () => location.y, + object: args.view, + eventName: toString(args.type) + }; +} + function _getPinchData(args: GestureEventData): PinchGestureEventData { const recognizer = args.ios; const center = recognizer.locationInView(args.view.nativeViewProtected);