Skip to content

Commit

Permalink
feat: report all touch positions
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Jan 2, 2020
1 parent e5d42d1 commit f147149
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/gesturehandler.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,17 @@ export abstract class Handler<T extends com.swmansion.gesturehandler.GestureHand
touchListener: com.swmansion.gesturehandler.OnTouchEventListener<T>;

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) {
Expand Down Expand Up @@ -440,6 +449,7 @@ export class PanGestureHandler extends Handler<com.swmansion.gesturehandler.PanG
}

export class PinchGestureHandler extends Handler<com.swmansion.gesturehandler.PinchGestureHandler, PinchGestureHandlerOptions> {
@nativeProperty({ converter: { fromNative: layout.toDevicePixels } }) minSpan: number;
createNative(options) {
return new com.swmansion.gesturehandler.PinchGestureHandler();
}
Expand Down Expand Up @@ -660,7 +670,6 @@ export class Manager extends ManagerBase {
} else {
throw new Error('a page is needed to attach a gesture');
}

}
}

Expand Down
7 changes: 3 additions & 4 deletions src/gesturehandler.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,19 @@ 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;
};
}
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;
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/gesturehandler.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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."
);
Expand Down
4 changes: 4 additions & 0 deletions src/typings/android.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>): boolean;
public handle(param0: globalAndroid.view.MotionEvent): void;
public setHitSlop(param0: number): T;
Expand All @@ -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<any>): boolean;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit f147149

Please sign in to comment.