Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions nativescript-core/ui/gestures/gestures.android.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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,
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 <SwipeGestureEventData>{
Expand Down
8 changes: 8 additions & 0 deletions nativescript-core/ui/gestures/gestures.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
22 changes: 20 additions & 2 deletions nativescript-core/ui/gestures/gestures.ios.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
getX: () => location.x,
getY: () => 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);
Expand Down