style(gestures): style updates

This commit is contained in:
Adam Bradley
2016-09-13 15:25:30 -05:00
parent 88b6524155
commit b8fb9c7c6d
10 changed files with 27 additions and 66 deletions

View File

@ -1,9 +1,8 @@
import { defaults } from '../util';
import { defaults } from '../util/util';
import { GestureDelegate } from '../gestures/gesture-controller';
import { PointerEvents, UIEventManager } from '../util/ui-event-manager';
import { PanRecognizer } from './recognizers';
import { pointerCoord, Coordinates } from '../util/dom';
import { PointerEvents, UIEventManager } from '../util/ui-event-manager';
import { pointerCoord } from '../util/dom';
/**
* @private
@ -19,7 +18,6 @@ export interface PanGestureConfig {
* @private
*/
export class PanGesture {
private dragging: boolean;
private events: UIEventManager = new UIEventManager(false);
private pointerEvents: PointerEvents;
private detector: PanRecognizer;

View File

@ -1,19 +1,16 @@
import { Injectable } from '@angular/core';
import { HammerGestureConfig } from '@angular/platform-browser';
/* this class override the default angular gesture config.
* The motivation for this is enabling pinch, rotate or
* any other multi-touch gestures block scrolling.
*/
/**
* @private
* This class overrides the default Angular gesture config.
*/
@Injectable()
export class IonicGestureConfig extends HammerGestureConfig {
buildHammer(element: HTMLElement) {
var mc = new (<any> window).Hammer(element);
const mc = new (<any> window).Hammer(element);
for (let eventName in this.overrides) {
mc.get(eventName).set(this.overrides[eventName]);

View File

@ -1,4 +1,3 @@
import { forwardRef, Inject, Injectable } from '@angular/core';
import { App } from '../components/app/app';

View File

@ -1,4 +1,4 @@
import { defaults, assign } from '../util';
import { defaults, assign } from '../util/util';
import { Hammer, DIRECTION_HORIZONTAL, DIRECTION_VERTICAL } from './hammer';
/**

View File

@ -1,7 +1,8 @@
import { pointerCoord, Coordinates } from '../util/dom';
import { PointerCoordinates } from '../util/dom';
export class PanRecognizer {
private startCoord: Coordinates;
private startCoord: PointerCoordinates;
private dirty: boolean = false;
private threshold: number;
private maxCosine: number;
@ -14,14 +15,14 @@ export class PanRecognizer {
this.threshold = threshold * threshold;
}
start(coord: Coordinates) {
start(coord: PointerCoordinates) {
this.startCoord = coord;
this._angle = 0;
this._isPan = 0;
this.dirty = true;
}
detect(coord: Coordinates): boolean {
detect(coord: PointerCoordinates): boolean {
if (!this.dirty) {
return false;
}

View File

@ -1,7 +1,7 @@
import { pointerCoord, Coordinates } from '../util/dom';
import { PointerCoordinates } from '../util/dom';
interface Point {
coord: Coordinates;
coord: PointerCoordinates;
duration: number;
}
@ -121,7 +121,7 @@ export class Simulate {
}
private newPoint(coord: Coordinates, duration: number) {
private newPoint(coord: PointerCoordinates, duration: number) {
this.points.push({
coord: coord,
duration: duration,
@ -149,13 +149,13 @@ function randomAngle(maxAngle: number): number {
return (Math.random() * maxAngle * 2) - maxAngle;
}
function distance(a: Coordinates, b: Coordinates): number {
function distance(a: PointerCoordinates, b: PointerCoordinates): number {
let deltaX = a.x - b.x;
let deltaY = a.y - a.y;
return Math.hypot(deltaX, deltaY);
}
function parseCoordinates(coord: Coordinates | number, y?: number): Coordinates {
function parseCoordinates(coord: PointerCoordinates | number, y?: number): PointerCoordinates {
if (typeof coord === 'number') {
return { x: coord, y: y };
}

View File

@ -1,5 +1,5 @@
import { PanGesture } from './drag-gesture';
import { clamp } from '../util';
import { clamp } from '../util/util';
import { pointerCoord } from '../util/dom';
/**

View File

@ -1,7 +1,6 @@
import { GestureController, DisableScroll } from '../../../src';
export function run() {
import { GestureController, DisableScroll } from '../gesture-controller';
describe('gesture controller', () => {
it('should create an instance of GestureController', () => {
let c = new GestureController(null);
expect(c.isCaptured()).toEqual(false);
@ -310,5 +309,4 @@ export function run() {
g.destroy();
expect(c.isScrollDisabled()).toEqual(false);
});
}
});

View File

@ -1,31 +0,0 @@
import { IonicGestureConfig } from '../../../src/gestures/ionic-gesture-config';
export function run() {
describe('IonicGestureConfig', () => {
it('should create a new instance of hammer', () => {
// arrange
let instance = new IonicGestureConfig();
let expectedParam = { name: "expectedParam"};
let expectedHammerInstance = { name: "hammer"};
let actualParam : any = null;
let callCount = 0;
(<any> window).Hammer = (param: any) => {
callCount++;
actualParam = param;
return expectedHammerInstance;
};
// act
let returnValue = instance.buildHammer( <HTMLElement> <any> expectedParam);
// assert
expect(returnValue.name).toEqual(expectedHammerInstance.name);
expect(callCount).toEqual(1);
expect(actualParam.name).toEqual(expectedParam.name);
});
})
}

View File

@ -1,9 +1,8 @@
import { PanRecognizer } from '../../../src/gestures/recognizers';
import { Simulate } from '../../../src/gestures/simulator';
export function run() {
import { PanRecognizer } from '../recognizers';
import { Simulate } from '../simulator';
describe('recognizers', () => {
it('should not fire if it did not start', () => {
let p = new PanRecognizer('x', 2, 2);
expect(p.pan()).toEqual(0);
@ -203,4 +202,4 @@ export function run() {
expect(p.pan()).toEqual(0);
});
}
});