mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +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 = new TouchGestureEventData();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._eventData.prepare(this.target, motionEvent);
|
this._eventData.prepare(this.target, motionEvent);
|
||||||
_executeCallback(this, this._eventData);
|
_executeCallback(this, this._eventData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,7 +468,7 @@ class CustomPanGestureDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private trackStart(currentEvent: android.view.MotionEvent) {
|
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.initialX = inital.x;
|
||||||
this.initialY = inital.y;
|
this.initialY = inital.y;
|
||||||
this.isTracking = true;
|
this.isTracking = true;
|
||||||
@ -478,7 +478,7 @@ class CustomPanGestureDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private trackChange(currentEvent: android.view.MotionEvent) {
|
private trackChange(currentEvent: android.view.MotionEvent) {
|
||||||
let current = this.getMotionEventCenter(currentEvent);
|
let current = this.getEventCoordinates(currentEvent);
|
||||||
this.deltaX = current.x - this.initialX;
|
this.deltaX = current.x - this.initialX;
|
||||||
this.deltaY = current.y - this.initialY;
|
this.deltaY = current.y - this.initialY;
|
||||||
|
|
||||||
@ -486,18 +486,28 @@ class CustomPanGestureDetector {
|
|||||||
_executeCallback(this.observer, args);
|
_executeCallback(this.observer, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getMotionEventCenter(event: android.view.MotionEvent): { x: number, y: number } {
|
private getEventCoordinates(event: android.view.MotionEvent): { x: number, y: number } {
|
||||||
let count = event.getPointerCount();
|
const count = event.getPointerCount();
|
||||||
let res = { x: 0, y: 0 };
|
if (count === 1) {
|
||||||
for (var i = 0; i < count; i++) {
|
return {
|
||||||
res.x += event.getX(i);
|
x: event.getRawX() / this.density,
|
||||||
res.y += event.getY(i);
|
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);
|
for (let i = 0; i < count; i++) {
|
||||||
res.y /= (count * this.density);
|
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