mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
Merge pull request #2118 from NativeScript/TheOriginalJosh-use-getRawX-Y-instead-of-getX-Y-to-allow-smoother-panning-coordinates
The original josh use get raw x y instead of get x y to allow smoother panning coordinates
This commit is contained in:
@ -110,7 +110,7 @@ export class GesturesObserver extends common.GesturesObserver {
|
||||
this._eventData = new TouchGestureEventData();
|
||||
}
|
||||
|
||||
this._eventData.prepare(this.target, motionEvent);
|
||||
this._eventData.prepare(this.target, motionEvent);
|
||||
_executeCallback(this, this._eventData);
|
||||
}
|
||||
|
||||
@ -468,7 +468,7 @@ class CustomPanGestureDetector {
|
||||
}
|
||||
|
||||
private trackStart(currentEvent: android.view.MotionEvent) {
|
||||
let inital = this.getMotionEventCenter(this.lastEventCache ? this.lastEventCache : currentEvent);
|
||||
let inital = this.getEventCoordinates(this.lastEventCache ? this.lastEventCache : currentEvent);
|
||||
this.initialX = inital.x;
|
||||
this.initialY = inital.y;
|
||||
this.isTracking = true;
|
||||
@ -478,7 +478,7 @@ class CustomPanGestureDetector {
|
||||
}
|
||||
|
||||
private trackChange(currentEvent: android.view.MotionEvent) {
|
||||
let current = this.getMotionEventCenter(currentEvent);
|
||||
let current = this.getEventCoordinates(currentEvent);
|
||||
this.deltaX = current.x - this.initialX;
|
||||
this.deltaY = current.y - this.initialY;
|
||||
|
||||
@ -486,18 +486,28 @@ class CustomPanGestureDetector {
|
||||
_executeCallback(this.observer, args);
|
||||
}
|
||||
|
||||
private getMotionEventCenter(event: android.view.MotionEvent): { x: number, y: number } {
|
||||
let count = event.getPointerCount();
|
||||
let res = { x: 0, y: 0 };
|
||||
for (var i = 0; i < count; i++) {
|
||||
res.x += event.getX(i);
|
||||
res.y += event.getY(i);
|
||||
private getEventCoordinates(event: android.view.MotionEvent): { x: number, y: number } {
|
||||
const count = event.getPointerCount();
|
||||
if (count === 1) {
|
||||
return {
|
||||
x: event.getRawX() / this.density,
|
||||
y: event.getRawY() / this.density
|
||||
};
|
||||
}
|
||||
else {
|
||||
const offX = event.getRawX() - event.getX();
|
||||
const offY = event.getRawY() - event.getY();
|
||||
let res = { x: 0, y: 0 };
|
||||
|
||||
res.x /= (count * this.density);
|
||||
res.y /= (count * this.density);
|
||||
for (let i = 0; i < count; i++) {
|
||||
res.x += event.getX(i) + offX;
|
||||
res.y += event.getY(i) + offY;
|
||||
}
|
||||
|
||||
return res;
|
||||
res.x /= (count * this.density);
|
||||
res.y /= (count * this.density);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user