mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Add getFocusX() and getFocusY() methods to PinchGestureEventData
This commit is contained in:
@ -216,32 +216,53 @@ class TapAndDoubleTapGestureListener extends android.view.GestureDetector.Simple
|
||||
}
|
||||
}
|
||||
|
||||
class PinchGestureEventData implements definition.PinchGestureEventData {
|
||||
public type = definition.GestureTypes.pinch;
|
||||
public eventName = definition.toString(definition.GestureTypes.pinch);
|
||||
public ios;
|
||||
|
||||
constructor(
|
||||
public view: view.View,
|
||||
public android: android.view.ScaleGestureDetector,
|
||||
public scale: number,
|
||||
public object: any,
|
||||
public state: common.GestureStateTypes) {
|
||||
|
||||
}
|
||||
|
||||
getFocusX(): number {
|
||||
return this.android.getFocusX() / utils.layout.getDisplayDensity();
|
||||
}
|
||||
getFocusY(): number {
|
||||
return this.android.getFocusY() / utils.layout.getDisplayDensity();
|
||||
}
|
||||
}
|
||||
|
||||
class PinchGestureListener extends android.view.ScaleGestureDetector.SimpleOnScaleGestureListener {
|
||||
private _observer: GesturesObserver;
|
||||
private _target: view.View;
|
||||
private _scale: number;
|
||||
private _density: number;
|
||||
|
||||
constructor(observer: GesturesObserver, target: view.View) {
|
||||
super();
|
||||
|
||||
this._observer = observer;
|
||||
this._target = target;
|
||||
|
||||
this._density = utils.layout.getDisplayDensity();
|
||||
|
||||
return global.__native(this);
|
||||
}
|
||||
|
||||
public onScaleBegin(detector: android.view.ScaleGestureDetector): boolean {
|
||||
this._scale = detector.getScaleFactor();
|
||||
|
||||
var args = <definition.PinchGestureEventData>{
|
||||
type: definition.GestureTypes.pinch,
|
||||
view: this._target,
|
||||
android: detector,
|
||||
scale: this._scale,
|
||||
object: this._target,
|
||||
eventName: definition.toString(definition.GestureTypes.pinch),
|
||||
ios: undefined,
|
||||
state: common.GestureStateTypes.began
|
||||
};
|
||||
var args = new PinchGestureEventData(
|
||||
this._target,
|
||||
detector,
|
||||
this._scale,
|
||||
this._target,
|
||||
common.GestureStateTypes.began);
|
||||
|
||||
_executeCallback(this._observer, args);
|
||||
|
||||
@ -251,16 +272,12 @@ class PinchGestureListener extends android.view.ScaleGestureDetector.SimpleOnSca
|
||||
public onScale(detector: android.view.ScaleGestureDetector): boolean {
|
||||
this._scale *= detector.getScaleFactor();
|
||||
|
||||
var args = <definition.PinchGestureEventData>{
|
||||
type: definition.GestureTypes.pinch,
|
||||
view: this._target,
|
||||
android: detector,
|
||||
scale: this._scale,
|
||||
object: this._target,
|
||||
eventName: definition.toString(definition.GestureTypes.pinch),
|
||||
ios: undefined,
|
||||
state: common.GestureStateTypes.changed
|
||||
};
|
||||
var args = new PinchGestureEventData(
|
||||
this._target,
|
||||
detector,
|
||||
this._scale,
|
||||
this._target,
|
||||
common.GestureStateTypes.changed);
|
||||
|
||||
_executeCallback(this._observer, args);
|
||||
return true;
|
||||
@ -269,16 +286,12 @@ class PinchGestureListener extends android.view.ScaleGestureDetector.SimpleOnSca
|
||||
public onScaleEnd(detector: android.view.ScaleGestureDetector): void {
|
||||
this._scale *= detector.getScaleFactor();
|
||||
|
||||
var args = <definition.PinchGestureEventData>{
|
||||
type: definition.GestureTypes.pinch,
|
||||
view: this._target,
|
||||
android: detector,
|
||||
scale: this._scale,
|
||||
object: this._target,
|
||||
eventName: definition.toString(definition.GestureTypes.pinch),
|
||||
ios: undefined,
|
||||
state: common.GestureStateTypes.ended
|
||||
};
|
||||
var args = new PinchGestureEventData(
|
||||
this._target,
|
||||
detector,
|
||||
this._scale,
|
||||
this._target,
|
||||
common.GestureStateTypes.ended);
|
||||
|
||||
_executeCallback(this._observer, args);
|
||||
}
|
||||
|
3
ui/gestures/gestures.d.ts
vendored
3
ui/gestures/gestures.d.ts
vendored
@ -117,6 +117,9 @@ declare module "ui/gestures" {
|
||||
*/
|
||||
export interface PinchGestureEventData extends GestureEventDataWithState {
|
||||
scale: number;
|
||||
|
||||
getFocusX(): number;
|
||||
getFocusY(): number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -273,12 +273,16 @@ function _getSwipeDirection(direction: UISwipeGestureRecognizerDirection): defin
|
||||
|
||||
function _getPinchData(args: definition.GestureEventData): definition.PinchGestureEventData {
|
||||
var recognizer = <UIPinchGestureRecognizer>args.ios;
|
||||
var center = recognizer.locationInView(args.view._nativeView);
|
||||
|
||||
return <definition.PinchGestureEventData>{
|
||||
type: args.type,
|
||||
view: args.view,
|
||||
ios: args.ios,
|
||||
android: undefined,
|
||||
scale: recognizer.scale,
|
||||
getFocusX: () => { return center.x; },
|
||||
getFocusY: () => { return center.y; },
|
||||
object: args.view,
|
||||
eventName: definition.toString(args.type),
|
||||
state: getState(recognizer)
|
||||
@ -287,6 +291,7 @@ function _getPinchData(args: definition.GestureEventData): definition.PinchGestu
|
||||
|
||||
function _getSwipeData(args: definition.GestureEventData): definition.SwipeGestureEventData {
|
||||
var recognizer = <UISwipeGestureRecognizer>args.ios;
|
||||
|
||||
return <definition.SwipeGestureEventData>{
|
||||
type: args.type,
|
||||
view: args.view,
|
||||
|
Reference in New Issue
Block a user