Skip to content

Commit 2b5e8e9

Browse files
authored
Merge pull request NativeScript#8338 from MCurran16/doubleTap-location
feat(gestures): add tap location getX() and getY() to double tap event data
2 parents 916ec8b + bf02f7a commit 2b5e8e9

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

nativescript-core/ui/gestures/gestures.android.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Definitions.
2-
import { GestureEventData, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, GestureEventDataWithState } from ".";
2+
import { DoubleTapGestureEventData, GestureEventData, GestureEventDataWithState, PanGestureEventData, RotationGestureEventData, SwipeGestureEventData } from ".";
33
import { View, EventData } from "../core/view";
44

55
// Types.
@@ -89,7 +89,7 @@ function initializeTapAndDoubleTapGestureListener() {
8989
timer.clearTimeout(this._tapTimeoutId);
9090
}
9191
if (this._type & GestureTypes.doubleTap) {
92-
const args = _getArgs(GestureTypes.doubleTap, this._target, motionEvent);
92+
const args = _getDoubleTapArgs(this._target, motionEvent);
9393
_executeCallback(this._observer, args);
9494
}
9595
}
@@ -395,6 +395,19 @@ function _getLongPressArgs(type: GestureTypes, view: View, state: GestureStateTy
395395
};
396396
}
397397

398+
function _getDoubleTapArgs(view: View, e: android.view.MotionEvent): DoubleTapGestureEventData {
399+
return <DoubleTapGestureEventData>{
400+
type: GestureTypes.doubleTap,
401+
view: view,
402+
android: e,
403+
getX: () => e.getX() / layout.getDisplayDensity(),
404+
getY: () => e.getY() / layout.getDisplayDensity(),
405+
ios: undefined,
406+
object: view,
407+
eventName: toString(GestureTypes.doubleTap),
408+
};
409+
}
410+
398411
function _getSwipeArgs(direction: SwipeDirection, view: View,
399412
initialEvent: android.view.MotionEvent, currentEvent: android.view.MotionEvent): SwipeGestureEventData {
400413
return <SwipeGestureEventData>{

nativescript-core/ui/gestures/gestures.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ export interface PinchGestureEventData extends GestureEventDataWithState {
212212
getFocusY(): number;
213213
}
214214

215+
/**
216+
* Provides gesture event data for double tap gesture.
217+
*/
218+
export interface DoubleTapGestureEventData extends GestureEventData {
219+
getX(): number;
220+
getY(): number;
221+
}
222+
215223
/**
216224
* Provides gesture event data for swipe gesture.
217225
*/

nativescript-core/ui/gestures/gestures.ios.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Definitions.
2-
import { GestureEventData, GestureEventDataWithState, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, PinchGestureEventData } from ".";
2+
import { DoubleTapGestureEventData, GestureEventData, GestureEventDataWithState, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, PinchGestureEventData } from ".";
33
import { View, EventData } from "../core/view";
44

55
// Types.
@@ -127,7 +127,9 @@ export class GesturesObserver extends GesturesObserverBase {
127127
}
128128

129129
if (type & GestureTypes.doubleTap) {
130-
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.doubleTap));
130+
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.doubleTap, args => {
131+
this._executeCallback(_getDoubleTapData(args));
132+
}));
131133
}
132134

133135
if (type & GestureTypes.pinch) {
@@ -298,6 +300,22 @@ function _getSwipeDirection(direction: UISwipeGestureRecognizerDirection): Swipe
298300
}
299301
}
300302

303+
function _getDoubleTapData(args: GestureEventData): DoubleTapGestureEventData {
304+
const recognizer = <UITapGestureRecognizer>args.ios;
305+
const location: CGPoint = recognizer.locationInView(args.view.nativeViewProtected);
306+
307+
return <DoubleTapGestureEventData>{
308+
type: args.type,
309+
view: args.view,
310+
ios: args.ios,
311+
android: undefined,
312+
getX: () => location.x,
313+
getY: () => location.y,
314+
object: args.view,
315+
eventName: toString(args.type)
316+
};
317+
}
318+
301319
function _getPinchData(args: GestureEventData): PinchGestureEventData {
302320
const recognizer = <UIPinchGestureRecognizer>args.ios;
303321
const center = recognizer.locationInView(args.view.nativeViewProtected);

0 commit comments

Comments
 (0)