Skip to content

Commit

Permalink
Merge branch '8.2.x' into ddincheva/summary5754
Browse files Browse the repository at this point in the history
  • Loading branch information
ddincheva authored Oct 10, 2019
2 parents d7d60ce + 6ce4040 commit a7f1db4
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 130 deletions.
50 changes: 32 additions & 18 deletions projects/igniteui-angular/src/lib/core/touch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Inject, Injectable, NgZone } from '@angular/core';
import { ɵgetDOM as getDOM } from '@angular/platform-browser';
import { DOCUMENT } from '@angular/common';
import { PlatformUtil } from './utils';

const EVENT_SUFFIX = 'precise';

Expand All @@ -11,26 +12,31 @@ const EVENT_SUFFIX = 'precise';
*/
@Injectable()
export class HammerGesturesManager {
private platformBrowser: boolean;
/**
* Event option defaults for each recognizer, see http://hammerjs.github.io/api/ for API listing.
*/
protected hammerOptions: HammerOptions = {
// D.P. #447 Force TouchInput due to PointerEventInput bug (https://github.com/hammerjs/hammer.js/issues/1065)
// see https://github.com/IgniteUI/igniteui-angular/issues/447#issuecomment-324601803
inputClass: Hammer.TouchInput,
recognizers: [
[ Hammer.Pan, { threshold: 0 } ],
[ Hammer.Swipe, {
direction: Hammer.DIRECTION_HORIZONTAL
}],
[Hammer.Tap],
[Hammer.Tap, { event: 'doubletap', taps: 2 }, ['tap']]
]
};
protected hammerOptions: HammerOptions = {};

private _hammerManagers: Array<{ element: EventTarget, manager: HammerManager; }> = [];

constructor(private _zone: NgZone, @Inject(DOCUMENT) private doc: any) {
constructor(private _zone: NgZone, @Inject(DOCUMENT) private doc: any, private platformUtil: PlatformUtil) {
this.platformBrowser = this.platformUtil.isBrowser;
if (this.platformBrowser) {
this.hammerOptions = {
// D.P. #447 Force TouchInput due to PointerEventInput bug (https://github.com/hammerjs/hammer.js/issues/1065)
// see https://github.com/IgniteUI/igniteui-angular/issues/447#issuecomment-324601803
inputClass: Hammer.TouchInput,
recognizers: [
[Hammer.Pan, { threshold: 0 }],
[Hammer.Swipe, {
direction: Hammer.DIRECTION_HORIZONTAL
}],
[Hammer.Tap],
[Hammer.Tap, { event: 'doubletap', taps: 2 }, ['tap']]
]
};
}
}

public supports(eventName: string): boolean {
Expand All @@ -41,10 +47,14 @@ export class HammerGesturesManager {
* Add listener extended with options for Hammer.js. Will use defaults if none are provided.
* Modeling after other event plugins for easy future modifications.
*/
public addEventListener(element: HTMLElement,
eventName: string,
eventHandler: (eventObj) => void,
options: HammerOptions = null): () => void {
public addEventListener(
element: HTMLElement,
eventName: string,
eventHandler: (eventObj) => void,
options: HammerOptions = null): () => void {
if (!this.platformBrowser) {
return;
}

// Creating the manager bind events, must be done outside of angular
return this._zone.runOutsideAngular(() => {
Expand All @@ -67,6 +77,10 @@ export class HammerGesturesManager {
* @param target Can be one of either window, body or document(fallback default).
*/
public addGlobalEventListener(target: string, eventName: string, eventHandler: (eventObj) => void): () => void {
if (!this.platformBrowser) {
return;
}

const element = this.getGlobalEventTarget(target);

// Creating the manager bind events, must be done outside of angular
Expand Down
47 changes: 39 additions & 8 deletions projects/igniteui-angular/src/lib/core/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { Injectable, PLATFORM_ID, Inject } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';

/**
*@hidden
*/
Expand Down Expand Up @@ -228,12 +231,14 @@ export function isFirefox(): boolean {

/**
* @hidden
* TODO: make injectable, check isPlatformBrowser()
*/
@Injectable({ providedIn: 'root' })
export class PlatformUtil {
static isIOS(): boolean {
const iosBrowser = typeof window !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window);
return iosBrowser;
public isBrowser: boolean = isPlatformBrowser(this.platformId);

public isIOS = this.isBrowser && /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window);

constructor(@Inject(PLATFORM_ID) private platformId: Object) {
}
}

Expand All @@ -246,8 +251,21 @@ export function isLeftClick(event: PointerEvent) {

/** @hidden */
export function isNavigationKey(key: string): boolean {
return ['down', 'up', 'left', 'right', 'arrowdown', 'arrowup', 'arrowleft', 'arrowright',
'home', 'end', 'space', 'spacebar', ' '].indexOf(key) !== -1;
return [
'down',
'up',
'left',
'right',
'arrowdown',
'arrowup',
'arrowleft',
'arrowright',
'home',
'end',
'space',
'spacebar',
' '
].indexOf(key) !== -1;
}

/**
Expand Down Expand Up @@ -285,8 +303,21 @@ export interface CancelableBrowserEventArgs extends CancelableEventArgs {
event?: Event;
}

export const NAVIGATION_KEYS = new Set(['down', 'up', 'left', 'right', 'arrowdown', 'arrowup', 'arrowleft', 'arrowright',
'home', 'end', 'space', 'spacebar', ' ']);
export const NAVIGATION_KEYS = new Set([
'down',
'up',
'left',
'right',
'arrowdown',
'arrowup',
'arrowleft',
'arrowright',
'home',
'end',
'space',
'spacebar',
' '
]);
export const ROW_EXPAND_KEYS = new Set('right down arrowright arrowdown'.split(' '));
export const ROW_COLLAPSE_KEYS = new Set('left up arrowleft arrowup'.split(' '));
export const SUPPORTED_KEYS = new Set([...Array.from(NAVIGATION_KEYS), 'tab', 'enter', 'f2', 'escape', 'esc']);
5 changes: 3 additions & 2 deletions projects/igniteui-angular/src/lib/grids/cell.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
public cdr: ChangeDetectorRef,
private element: ElementRef,
protected zone: NgZone,
private touchManager: HammerGesturesManager) { }
private touchManager: HammerGesturesManager,
protected platformUtil: PlatformUtil) { }

private addPointerListeners(selection) {
if (selection !== GridSelectionMode.multiple) { return; }
Expand Down Expand Up @@ -590,7 +591,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
this.nativeElement.addEventListener('compositionend', this.compositionEndHandler);
}
});
if (PlatformUtil.isIOS()) {
if (this.platformUtil.isIOS) {
this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
cssProps: { } /* don't disable user-select, etc */
} as HammerOptions);
Expand Down
15 changes: 12 additions & 3 deletions projects/igniteui-angular/src/lib/grids/grid/cell.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,26 @@ describe('IgxGrid - Cell component #grid', () => {

it('Should not attach doubletap handler for non-iOS', () => {
const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener');
spyOn(PlatformUtil, 'isIOS').and.returnValue(false);
const platformUtil: PlatformUtil = TestBed.get(PlatformUtil);
const oldIsIOS = platformUtil.isIOS;
platformUtil.isIOS = false;
const fix = TestBed.createComponent(DefaultGridComponent);
fix.detectChanges();
// spyOnProperty(PlatformUtil.prototype, 'isIOS').and.returnValue(false);
expect(addListenerSpy).not.toHaveBeenCalled();

platformUtil.isIOS = oldIsIOS;
});

it('Should handle doubletap on iOS, trigger onDoubleClick event', () => {
const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener');
spyOn(PlatformUtil, 'isIOS').and.returnValue(true);
const platformUtil: PlatformUtil = TestBed.get(PlatformUtil);
const oldIsIOS = platformUtil.isIOS;
platformUtil.isIOS = true;
const fix = TestBed.createComponent(DefaultGridComponent);
fix.detectChanges();

const grid = fix.componentInstance.instance;
const cellElem = fix.debugElement.query(By.css(CELL_CSS_CLASS));
const firstCell = grid.getCellByColumn(0, 'index');

// should attach 'doubletap'
Expand All @@ -217,6 +224,8 @@ describe('IgxGrid - Cell component #grid', () => {
expect(event.preventDefault).toHaveBeenCalled();
expect(grid.onDoubleClick.emit).toHaveBeenCalledWith(args);
expect(firstCell).toBe(fix.componentInstance.clickedCell);

platformUtil.isIOS = oldIsIOS;
});

it('Should blur selected cell when scrolling with mouse wheel', (async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IgxHierarchicalGridComponent } from './hierarchical-grid.component';
// import { IgxHierarchicalSelectionAPIService } from './selection';
import { IgxGridSelectionService, IgxGridCRUDService } from '../../core/grid-selection';
import { HammerGesturesManager } from '../../core/touch';
import { PlatformUtil } from '../../core/utils';

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
Expand All @@ -27,9 +28,10 @@ export class IgxHierarchicalGridCellComponent extends IgxGridCellComponent imple
public cdr: ChangeDetectorRef,
private helement: ElementRef,
protected zone: NgZone,
touchManager: HammerGesturesManager
touchManager: HammerGesturesManager,
protected platformUtil: PlatformUtil
) {
super(selectionService, crudService, gridAPI, cdr, helement, zone, touchManager);
super(selectionService, crudService, gridAPI, cdr, helement, zone, touchManager, platformUtil);
// this.hSelection = <IgxHierarchicalSelectionAPIService>selection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Component, ChangeDetectorRef, ElementRef, ViewChild, Inject,
import { IgxGridCellComponent } from '../cell.component';
import { IgxTreeGridAPIService } from './tree-grid-api.service';
import { GridBaseAPIService } from '../api.service';
import { getNodeSizeViaRange } from '../../core/utils';
import { getNodeSizeViaRange, PlatformUtil } from '../../core/utils';
import { DOCUMENT } from '@angular/common';
import { IgxGridBaseComponent, IGridDataBindable } from '../grid';
import { IgxGridSelectionService, IgxGridCRUDService } from '../../core/grid-selection';
Expand All @@ -26,8 +26,9 @@ export class IgxTreeGridCellComponent extends IgxGridCellComponent implements On
element: ElementRef,
protected zone: NgZone,
touchManager: HammerGesturesManager,
@Inject(DOCUMENT) public document) {
super(selectionService, crudService, gridAPI, cdr, element, zone, touchManager);
@Inject(DOCUMENT) public document,
protected platformUtil: PlatformUtil) {
super(selectionService, crudService, gridAPI, cdr, element, zone, touchManager, platformUtil);
this.treeGridAPI = <IgxTreeGridAPIService>gridAPI;
}

Expand Down
Loading

0 comments on commit a7f1db4

Please sign in to comment.