From 5ff78e2ad2612259bff36d3aaf5a0292309f5a78 Mon Sep 17 00:00:00 2001 From: lukecurran Date: Thu, 13 Feb 2020 14:57:56 -0600 Subject: [PATCH 1/3] feat(gestures): add locationX and locationY to double tap event data --- .../ui/gestures/gestures.android.ts | 17 ++++++++++++-- nativescript-core/ui/gestures/gestures.d.ts | 8 +++++++ nativescript-core/ui/gestures/gestures.ios.ts | 22 +++++++++++++++++-- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/nativescript-core/ui/gestures/gestures.android.ts b/nativescript-core/ui/gestures/gestures.android.ts index 3b3de4bc3..0989e01ff 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, + 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 { diff --git a/nativescript-core/ui/gestures/gestures.d.ts b/nativescript-core/ui/gestures/gestures.d.ts index 886cc2ad8..57c9e64cb 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 { + locationX: number; + locationY: 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..f0cf31372 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, + locationX: location.x, + locationY: 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); From 520878a8a0930d70f0495a018b9914cd7698112c Mon Sep 17 00:00:00 2001 From: lukecurran Date: Thu, 13 Feb 2020 15:30:46 -0600 Subject: [PATCH 2/3] tslint --- .../ui/gestures/gestures.android.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/nativescript-core/ui/gestures/gestures.android.ts b/nativescript-core/ui/gestures/gestures.android.ts index 0989e01ff..d1a146c18 100644 --- a/nativescript-core/ui/gestures/gestures.android.ts +++ b/nativescript-core/ui/gestures/gestures.android.ts @@ -396,16 +396,16 @@ 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, - locationX: e.getX() / layout.getDisplayDensity(), - locationY: e.getY() / layout.getDisplayDensity(), - ios: undefined, - object: view, - eventName: toString(GestureTypes.doubleTap), - }; + return { + 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, From 46628ffdb144ab71a0c2caf615797540bff223a6 Mon Sep 17 00:00:00 2001 From: lukecurran Date: Fri, 6 Mar 2020 10:25:37 -0600 Subject: [PATCH 3/3] refact: locationX/locationY -> getX()/getY() --- nativescript-core/ui/gestures/gestures.android.ts | 4 ++-- nativescript-core/ui/gestures/gestures.d.ts | 4 ++-- nativescript-core/ui/gestures/gestures.ios.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nativescript-core/ui/gestures/gestures.android.ts b/nativescript-core/ui/gestures/gestures.android.ts index d1a146c18..d90171f0d 100644 --- a/nativescript-core/ui/gestures/gestures.android.ts +++ b/nativescript-core/ui/gestures/gestures.android.ts @@ -400,8 +400,8 @@ function _getDoubleTapArgs(view: View, e: android.view.MotionEvent): DoubleTapGe type: GestureTypes.doubleTap, view: view, android: e, - locationX: e.getX() / layout.getDisplayDensity(), - locationY: e.getY() / layout.getDisplayDensity(), + getX: () => e.getX() / layout.getDisplayDensity(), + getY: () => e.getY() / layout.getDisplayDensity(), ios: undefined, object: view, eventName: toString(GestureTypes.doubleTap), diff --git a/nativescript-core/ui/gestures/gestures.d.ts b/nativescript-core/ui/gestures/gestures.d.ts index 57c9e64cb..7c66d18ff 100644 --- a/nativescript-core/ui/gestures/gestures.d.ts +++ b/nativescript-core/ui/gestures/gestures.d.ts @@ -216,8 +216,8 @@ export interface PinchGestureEventData extends GestureEventDataWithState { * Provides gesture event data for double tap gesture. */ export interface DoubleTapGestureEventData extends GestureEventData { - locationX: number; - locationY: number; + getX(): number; + getY(): number; } /** diff --git a/nativescript-core/ui/gestures/gestures.ios.ts b/nativescript-core/ui/gestures/gestures.ios.ts index f0cf31372..2f36f938f 100644 --- a/nativescript-core/ui/gestures/gestures.ios.ts +++ b/nativescript-core/ui/gestures/gestures.ios.ts @@ -309,8 +309,8 @@ function _getDoubleTapData(args: GestureEventData): DoubleTapGestureEventData { view: args.view, ios: args.ios, android: undefined, - locationX: location.x, - locationY: location.y, + getX: () => location.x, + getY: () => location.y, object: args.view, eventName: toString(args.type) };