Merge pull request #8224 from NativeScript/niliev/long-press

feat: add longPress state argument w/ UILongPressGestureRecognizer (iOS)
This commit is contained in:
Dimitar Topuzov
2020-01-06 22:01:58 +02:00
committed by GitHub
2 changed files with 32 additions and 4 deletions

View File

@@ -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 <GestureEventDataWithState>{
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 <SwipeGestureEventData>{

View File

@@ -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 = <UILongPressGestureRecognizer>args.ios;
return <GestureEventDataWithState>{
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;