mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Merge pull request #8338 from MCurran16/doubleTap-location
feat(gestures): add tap location getX() and getY() to double tap event data
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
// Definitions.
|
// Definitions.
|
||||||
import { GestureEventData, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, GestureEventDataWithState } from ".";
|
import { DoubleTapGestureEventData, GestureEventData, GestureEventDataWithState, PanGestureEventData, RotationGestureEventData, SwipeGestureEventData } from ".";
|
||||||
import { View, EventData } from "../core/view";
|
import { View, EventData } from "../core/view";
|
||||||
|
|
||||||
// Types.
|
// Types.
|
||||||
@ -89,7 +89,7 @@ function initializeTapAndDoubleTapGestureListener() {
|
|||||||
timer.clearTimeout(this._tapTimeoutId);
|
timer.clearTimeout(this._tapTimeoutId);
|
||||||
}
|
}
|
||||||
if (this._type & GestureTypes.doubleTap) {
|
if (this._type & GestureTypes.doubleTap) {
|
||||||
const args = _getArgs(GestureTypes.doubleTap, this._target, motionEvent);
|
const args = _getDoubleTapArgs(this._target, motionEvent);
|
||||||
_executeCallback(this._observer, args);
|
_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,
|
||||||
|
getX: () => e.getX() / layout.getDisplayDensity(),
|
||||||
|
getY: () => e.getY() / layout.getDisplayDensity(),
|
||||||
|
ios: undefined,
|
||||||
|
object: view,
|
||||||
|
eventName: toString(GestureTypes.doubleTap),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function _getSwipeArgs(direction: SwipeDirection, view: View,
|
function _getSwipeArgs(direction: SwipeDirection, view: View,
|
||||||
initialEvent: android.view.MotionEvent, currentEvent: android.view.MotionEvent): SwipeGestureEventData {
|
initialEvent: android.view.MotionEvent, currentEvent: android.view.MotionEvent): SwipeGestureEventData {
|
||||||
return <SwipeGestureEventData>{
|
return <SwipeGestureEventData>{
|
||||||
|
8
nativescript-core/ui/gestures/gestures.d.ts
vendored
8
nativescript-core/ui/gestures/gestures.d.ts
vendored
@ -212,6 +212,14 @@ export interface PinchGestureEventData extends GestureEventDataWithState {
|
|||||||
getFocusY(): number;
|
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.
|
* Provides gesture event data for swipe gesture.
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Definitions.
|
// Definitions.
|
||||||
import { GestureEventData, GestureEventDataWithState, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, PinchGestureEventData } from ".";
|
import { DoubleTapGestureEventData, GestureEventData, GestureEventDataWithState, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, PinchGestureEventData } from ".";
|
||||||
import { View, EventData } from "../core/view";
|
import { View, EventData } from "../core/view";
|
||||||
|
|
||||||
// Types.
|
// Types.
|
||||||
@ -127,7 +127,9 @@ export class GesturesObserver extends GesturesObserverBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type & GestureTypes.doubleTap) {
|
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) {
|
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,
|
||||||
|
getX: () => location.x,
|
||||||
|
getY: () => location.y,
|
||||||
|
object: args.view,
|
||||||
|
eventName: toString(args.type)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function _getPinchData(args: GestureEventData): PinchGestureEventData {
|
function _getPinchData(args: GestureEventData): PinchGestureEventData {
|
||||||
const recognizer = <UIPinchGestureRecognizer>args.ios;
|
const recognizer = <UIPinchGestureRecognizer>args.ios;
|
||||||
const center = recognizer.locationInView(args.view.nativeViewProtected);
|
const center = recognizer.locationInView(args.view.nativeViewProtected);
|
||||||
|
Reference in New Issue
Block a user