diff --git a/nativescript-core/ui/gestures/gestures.android.ts b/nativescript-core/ui/gestures/gestures.android.ts index 4c60aa53c..3b3de4bc3 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 } from "."; +import { GestureEventData, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, GestureEventDataWithState } from "."; import { View, EventData } from "../core/view"; // Types. @@ -62,7 +62,7 @@ function initializeTapAndDoubleTapGestureListener() { public onLongPress(motionEvent: android.view.MotionEvent): void { if (this._type & GestureTypes.longPress) { - const args = _getArgs(GestureTypes.longPress, this._target, motionEvent); + const args = _getLongPressArgs(GestureTypes.longPress, this._target, GestureStateTypes.began, motionEvent); _executeCallback(this._observer, args); } } @@ -383,6 +383,18 @@ function _getArgs(type: GestureTypes, view: View, e: android.view.MotionEvent): }; } +function _getLongPressArgs(type: GestureTypes, view: View, state: GestureStateTypes, e: android.view.MotionEvent): GestureEventDataWithState { + return { + type: type, + view: view, + android: e, + ios: undefined, + object: view, + eventName: toString(type), + state: state + }; +} + function _getSwipeArgs(direction: SwipeDirection, view: View, initialEvent: android.view.MotionEvent, currentEvent: android.view.MotionEvent): SwipeGestureEventData { return { diff --git a/nativescript-core/ui/gestures/gestures.ios.ts b/nativescript-core/ui/gestures/gestures.ios.ts index 7ecb87657..d687b9092 100644 --- a/nativescript-core/ui/gestures/gestures.ios.ts +++ b/nativescript-core/ui/gestures/gestures.ios.ts @@ -1,5 +1,5 @@ // Definitions. -import { GestureEventData, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, PinchGestureEventData } from "."; +import { GestureEventData, GestureEventDataWithState, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, PinchGestureEventData } from "."; import { View, EventData } from "../core/view"; // Types. @@ -167,7 +167,9 @@ export class GesturesObserver extends GesturesObserverBase { } if (type & GestureTypes.longPress) { - nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.longPress)); + nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.longPress, args => { + this._executeCallback(_getLongPressData(args)); + })); } if (type & GestureTypes.touch) { @@ -359,6 +361,20 @@ function _getRotationData(args: GestureEventData): RotationGestureEventData { }; } +function _getLongPressData(args: GestureEventData): GestureEventDataWithState { + const recognizer = args.ios; + + return { + type: args.type, + view: args.view, + ios: args.ios, + android: undefined, + object: args.view, + eventName: toString(args.type), + state: getState(recognizer) + }; +} + class TouchGestureRecognizer extends UIGestureRecognizer { public observer: GesturesObserver; private _eventData: TouchGestureEventData;