Skip to content

Commit 416f1c8

Browse files
committed
feat: add longPress state with UIGestureRecognizer (iOS)
1 parent 217d22e commit 416f1c8

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

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

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

55
// Types.
@@ -62,7 +62,7 @@ function initializeTapAndDoubleTapGestureListener() {
6262

6363
public onLongPress(motionEvent: android.view.MotionEvent): void {
6464
if (this._type & GestureTypes.longPress) {
65-
const args = _getArgs(GestureTypes.longPress, this._target, motionEvent);
65+
const args = _getLongPressArgs(GestureTypes.longPress, this._target, GestureStateTypes.began, motionEvent);
6666
_executeCallback(this._observer, args);
6767
}
6868
}
@@ -383,6 +383,18 @@ function _getArgs(type: GestureTypes, view: View, e: android.view.MotionEvent):
383383
};
384384
}
385385

386+
function _getLongPressArgs(type: GestureTypes, view: View, state: GestureStateTypes, e: android.view.MotionEvent): GestureEventDataWithState {
387+
return <GestureEventDataWithState>{
388+
type: type,
389+
view: view,
390+
android: e,
391+
ios: undefined,
392+
object: view,
393+
eventName: toString(type),
394+
state: state
395+
};
396+
}
397+
386398
function _getSwipeArgs(direction: SwipeDirection, view: View,
387399
initialEvent: android.view.MotionEvent, currentEvent: android.view.MotionEvent): SwipeGestureEventData {
388400
return <SwipeGestureEventData>{

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

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

55
// Types.
@@ -167,7 +167,9 @@ export class GesturesObserver extends GesturesObserverBase {
167167
}
168168

169169
if (type & GestureTypes.longPress) {
170-
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.longPress));
170+
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.longPress, args => {
171+
this._executeCallback(_getLongPressData(args));
172+
}));
171173
}
172174

173175
if (type & GestureTypes.touch) {
@@ -359,6 +361,20 @@ function _getRotationData(args: GestureEventData): RotationGestureEventData {
359361
};
360362
}
361363

364+
function _getLongPressData(args: GestureEventData): GestureEventDataWithState {
365+
const recognizer = <UILongPressGestureRecognizer>args.ios;
366+
367+
return <GestureEventDataWithState>{
368+
type: args.type,
369+
view: args.view,
370+
ios: args.ios,
371+
android: undefined,
372+
object: args.view,
373+
eventName: toString(args.type),
374+
state: getState(recognizer)
375+
};
376+
}
377+
362378
class TouchGestureRecognizer extends UIGestureRecognizer {
363379
public observer: GesturesObserver;
364380
private _eventData: TouchGestureEventData;

0 commit comments

Comments
 (0)