From f1471490bdf163f21c76bd5858dc93d53fc52805 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Thu, 2 Jan 2020 13:36:53 +0100 Subject: [PATCH] feat: report all touch positions --- src/gesturehandler.android.ts | 13 +++++++++++-- src/gesturehandler.common.ts | 7 +++---- src/gesturehandler.ios.ts | 2 +- src/typings/android.d.ts | 4 ++++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/gesturehandler.android.ts b/src/gesturehandler.android.ts index 0757839..0f48d08 100644 --- a/src/gesturehandler.android.ts +++ b/src/gesturehandler.android.ts @@ -308,8 +308,17 @@ export abstract class Handler; getExtraData(handler: T) { + const numberOfPointers = handler.getNumberOfPointers(); + const positions = []; + for (let index = 0; index < numberOfPointers; index++) { + positions.push(handler.getXAtIndex(index)); + positions.push(handler.getYAtIndex(index)); + } return { - numberOfPointers: handler.getNumberOfPointers() + // x: layout.toDeviceIndependentPixels(handler.getX()), + // y: layout.toDeviceIndependentPixels(handler.getY()), + positions, + numberOfPointers }; } initNativeView(native: T, options: U) { @@ -440,6 +449,7 @@ export class PanGestureHandler extends Handler { + @nativeProperty({ converter: { fromNative: layout.toDevicePixels } }) minSpan: number; createNative(options) { return new com.swmansion.gesturehandler.PinchGestureHandler(); } @@ -660,7 +670,6 @@ export class Manager extends ManagerBase { } else { throw new Error('a page is needed to attach a gesture'); } - } } diff --git a/src/gesturehandler.common.ts b/src/gesturehandler.common.ts index 3983fb2..909b432 100644 --- a/src/gesturehandler.common.ts +++ b/src/gesturehandler.common.ts @@ -71,7 +71,7 @@ function createGetter(key: string, options: NativePropertyOptions) { } else { result = this.options[key] || options.defaultValue; } - result = converter ? converter.fromNative.call(this, result, key) : result; + result = converter && converter.fromNative ? converter.fromNative.call(this, result, key) : result; // console.log('getter', key, options, nativeGetterName, !!getConverter, result); return result; }; @@ -79,12 +79,11 @@ function createGetter(key: string, options: NativePropertyOptions) { function createSetter(key, options: NativePropertyOptions) { const nativeSetterName = ((isAndroid ? options.android : options.ios) || options).nativeSetterName || 'set' + key.charAt(0).toUpperCase() + key.slice(1); return function(newVal) { - // console.log('setter', key, newVal, Array.isArray(newVal), typeof newVal, nativeSetterName, options.converter); this.options[key] = newVal; if (this.native && this.native[nativeSetterName]) { - const actualVal = options.converter ? options.converter.toNative.call(this, newVal, key) : newVal; + const actualVal = options.converter && options.converter.toNative ? options.converter.toNative.call(this, newVal, key) : newVal; + console.log('setter', key, newVal, Array.isArray(newVal), typeof newVal, actualVal, nativeSetterName, options.converter, this.native && this.native[nativeSetterName]); (this.native[nativeSetterName] as Function).call(this.native, ...actualVal); - this._buildStyle = null; } }; } diff --git a/src/gesturehandler.ios.ts b/src/gesturehandler.ios.ts index e6f3f99..a8b769d 100644 --- a/src/gesturehandler.ios.ts +++ b/src/gesturehandler.ios.ts @@ -73,7 +73,7 @@ function getValueForClass(val) { default: console.log( - "Please report this at https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues: iOS toJsObject is missing a converter for class '" + + "Please report this at https://github.com/farfromrefug/nativescript-gesturehandler-febase/issues: iOS toJsObject is missing a converter for class '" + getClass(val) + "'. Casting to String as a fallback." ); diff --git a/src/typings/android.d.ts b/src/typings/android.d.ts index 2568a38..4d2c1a1 100644 --- a/src/typings/android.d.ts +++ b/src/typings/android.d.ts @@ -68,6 +68,7 @@ declare module com { public getLastAbsolutePositionX(): number; public onCancel(): void; public getY(): number; + public getYAtIndex(index: number): number; public shouldWaitForHandlerFailure(param0: com.swmansion.gesturehandler.GestureHandler): boolean; public handle(param0: globalAndroid.view.MotionEvent): void; public setHitSlop(param0: number): T; @@ -83,6 +84,7 @@ declare module com { public stopTrackingPointer(param0: number): void; public setInteractionController(param0: com.swmansion.gesturehandler.GestureHandlerInteractionController): T; public getX(): number; + public getXAtIndex(index:number): number; public startTrackingPointer(param0: number): void; public activate(): void; public shouldBeCancelledBy(param0: com.swmansion.gesturehandler.GestureHandler): boolean; @@ -297,6 +299,8 @@ declare module com { public getVelocity(): number; public getFocalPointX(): number; public getFocalPointY(): number; + public getMinSpan(): number; + public setMinSpan(span: number); public onHandle(param0: globalAndroid.view.MotionEvent): void; public constructor(); }