Skip to content

Commit a7f1db4

Browse files
authored
Merge branch '8.2.x' into ddincheva/summary5754
2 parents d7d60ce + 6ce4040 commit a7f1db4

File tree

8 files changed

+195
-130
lines changed

8 files changed

+195
-130
lines changed

projects/igniteui-angular/src/lib/core/touch.ts

+32-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Inject, Injectable, NgZone } from '@angular/core';
22
import { ɵgetDOM as getDOM } from '@angular/platform-browser';
33
import { DOCUMENT } from '@angular/common';
4+
import { PlatformUtil } from './utils';
45

56
const EVENT_SUFFIX = 'precise';
67

@@ -11,26 +12,31 @@ const EVENT_SUFFIX = 'precise';
1112
*/
1213
@Injectable()
1314
export class HammerGesturesManager {
15+
private platformBrowser: boolean;
1416
/**
1517
* Event option defaults for each recognizer, see http://hammerjs.github.io/api/ for API listing.
1618
*/
17-
protected hammerOptions: HammerOptions = {
18-
// D.P. #447 Force TouchInput due to PointerEventInput bug (https://github.com/hammerjs/hammer.js/issues/1065)
19-
// see https://github.com/IgniteUI/igniteui-angular/issues/447#issuecomment-324601803
20-
inputClass: Hammer.TouchInput,
21-
recognizers: [
22-
[ Hammer.Pan, { threshold: 0 } ],
23-
[ Hammer.Swipe, {
24-
direction: Hammer.DIRECTION_HORIZONTAL
25-
}],
26-
[Hammer.Tap],
27-
[Hammer.Tap, { event: 'doubletap', taps: 2 }, ['tap']]
28-
]
29-
};
19+
protected hammerOptions: HammerOptions = {};
3020

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

33-
constructor(private _zone: NgZone, @Inject(DOCUMENT) private doc: any) {
23+
constructor(private _zone: NgZone, @Inject(DOCUMENT) private doc: any, private platformUtil: PlatformUtil) {
24+
this.platformBrowser = this.platformUtil.isBrowser;
25+
if (this.platformBrowser) {
26+
this.hammerOptions = {
27+
// D.P. #447 Force TouchInput due to PointerEventInput bug (https://github.com/hammerjs/hammer.js/issues/1065)
28+
// see https://github.com/IgniteUI/igniteui-angular/issues/447#issuecomment-324601803
29+
inputClass: Hammer.TouchInput,
30+
recognizers: [
31+
[Hammer.Pan, { threshold: 0 }],
32+
[Hammer.Swipe, {
33+
direction: Hammer.DIRECTION_HORIZONTAL
34+
}],
35+
[Hammer.Tap],
36+
[Hammer.Tap, { event: 'doubletap', taps: 2 }, ['tap']]
37+
]
38+
};
39+
}
3440
}
3541

3642
public supports(eventName: string): boolean {
@@ -41,10 +47,14 @@ export class HammerGesturesManager {
4147
* Add listener extended with options for Hammer.js. Will use defaults if none are provided.
4248
* Modeling after other event plugins for easy future modifications.
4349
*/
44-
public addEventListener(element: HTMLElement,
45-
eventName: string,
46-
eventHandler: (eventObj) => void,
47-
options: HammerOptions = null): () => void {
50+
public addEventListener(
51+
element: HTMLElement,
52+
eventName: string,
53+
eventHandler: (eventObj) => void,
54+
options: HammerOptions = null): () => void {
55+
if (!this.platformBrowser) {
56+
return;
57+
}
4858

4959
// Creating the manager bind events, must be done outside of angular
5060
return this._zone.runOutsideAngular(() => {
@@ -67,6 +77,10 @@ export class HammerGesturesManager {
6777
* @param target Can be one of either window, body or document(fallback default).
6878
*/
6979
public addGlobalEventListener(target: string, eventName: string, eventHandler: (eventObj) => void): () => void {
80+
if (!this.platformBrowser) {
81+
return;
82+
}
83+
7084
const element = this.getGlobalEventTarget(target);
7185

7286
// Creating the manager bind events, must be done outside of angular

projects/igniteui-angular/src/lib/core/utils.ts

+39-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { Injectable, PLATFORM_ID, Inject } from '@angular/core';
2+
import { isPlatformBrowser } from '@angular/common';
3+
14
/**
25
*@hidden
36
*/
@@ -228,12 +231,14 @@ export function isFirefox(): boolean {
228231

229232
/**
230233
* @hidden
231-
* TODO: make injectable, check isPlatformBrowser()
232234
*/
235+
@Injectable({ providedIn: 'root' })
233236
export class PlatformUtil {
234-
static isIOS(): boolean {
235-
const iosBrowser = typeof window !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window);
236-
return iosBrowser;
237+
public isBrowser: boolean = isPlatformBrowser(this.platformId);
238+
239+
public isIOS = this.isBrowser && /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window);
240+
241+
constructor(@Inject(PLATFORM_ID) private platformId: Object) {
237242
}
238243
}
239244

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

247252
/** @hidden */
248253
export function isNavigationKey(key: string): boolean {
249-
return ['down', 'up', 'left', 'right', 'arrowdown', 'arrowup', 'arrowleft', 'arrowright',
250-
'home', 'end', 'space', 'spacebar', ' '].indexOf(key) !== -1;
254+
return [
255+
'down',
256+
'up',
257+
'left',
258+
'right',
259+
'arrowdown',
260+
'arrowup',
261+
'arrowleft',
262+
'arrowright',
263+
'home',
264+
'end',
265+
'space',
266+
'spacebar',
267+
' '
268+
].indexOf(key) !== -1;
251269
}
252270

253271
/**
@@ -285,8 +303,21 @@ export interface CancelableBrowserEventArgs extends CancelableEventArgs {
285303
event?: Event;
286304
}
287305

288-
export const NAVIGATION_KEYS = new Set(['down', 'up', 'left', 'right', 'arrowdown', 'arrowup', 'arrowleft', 'arrowright',
289-
'home', 'end', 'space', 'spacebar', ' ']);
306+
export const NAVIGATION_KEYS = new Set([
307+
'down',
308+
'up',
309+
'left',
310+
'right',
311+
'arrowdown',
312+
'arrowup',
313+
'arrowleft',
314+
'arrowright',
315+
'home',
316+
'end',
317+
'space',
318+
'spacebar',
319+
' '
320+
]);
290321
export const ROW_EXPAND_KEYS = new Set('right down arrowright arrowdown'.split(' '));
291322
export const ROW_COLLAPSE_KEYS = new Set('left up arrowleft arrowup'.split(' '));
292323
export const SUPPORTED_KEYS = new Set([...Array.from(NAVIGATION_KEYS), 'tab', 'enter', 'f2', 'escape', 'esc']);

projects/igniteui-angular/src/lib/grids/cell.component.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
558558
public cdr: ChangeDetectorRef,
559559
private element: ElementRef,
560560
protected zone: NgZone,
561-
private touchManager: HammerGesturesManager) { }
561+
private touchManager: HammerGesturesManager,
562+
protected platformUtil: PlatformUtil) { }
562563

563564
private addPointerListeners(selection) {
564565
if (selection !== GridSelectionMode.multiple) { return; }
@@ -590,7 +591,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
590591
this.nativeElement.addEventListener('compositionend', this.compositionEndHandler);
591592
}
592593
});
593-
if (PlatformUtil.isIOS()) {
594+
if (this.platformUtil.isIOS) {
594595
this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
595596
cssProps: { } /* don't disable user-select, etc */
596597
} as HammerOptions);

projects/igniteui-angular/src/lib/grids/grid/cell.spec.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,26 @@ describe('IgxGrid - Cell component #grid', () => {
182182

183183
it('Should not attach doubletap handler for non-iOS', () => {
184184
const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener');
185-
spyOn(PlatformUtil, 'isIOS').and.returnValue(false);
185+
const platformUtil: PlatformUtil = TestBed.get(PlatformUtil);
186+
const oldIsIOS = platformUtil.isIOS;
187+
platformUtil.isIOS = false;
186188
const fix = TestBed.createComponent(DefaultGridComponent);
187189
fix.detectChanges();
190+
// spyOnProperty(PlatformUtil.prototype, 'isIOS').and.returnValue(false);
191+
expect(addListenerSpy).not.toHaveBeenCalled();
192+
193+
platformUtil.isIOS = oldIsIOS;
188194
});
189195

190196
it('Should handle doubletap on iOS, trigger onDoubleClick event', () => {
191197
const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener');
192-
spyOn(PlatformUtil, 'isIOS').and.returnValue(true);
198+
const platformUtil: PlatformUtil = TestBed.get(PlatformUtil);
199+
const oldIsIOS = platformUtil.isIOS;
200+
platformUtil.isIOS = true;
193201
const fix = TestBed.createComponent(DefaultGridComponent);
194202
fix.detectChanges();
195203

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

200207
// should attach 'doubletap'
@@ -217,6 +224,8 @@ describe('IgxGrid - Cell component #grid', () => {
217224
expect(event.preventDefault).toHaveBeenCalled();
218225
expect(grid.onDoubleClick.emit).toHaveBeenCalledWith(args);
219226
expect(firstCell).toBe(fix.componentInstance.clickedCell);
227+
228+
platformUtil.isIOS = oldIsIOS;
220229
});
221230

222231
it('Should blur selected cell when scrolling with mouse wheel', (async () => {

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-cell.component.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { IgxHierarchicalGridComponent } from './hierarchical-grid.component';
66
// import { IgxHierarchicalSelectionAPIService } from './selection';
77
import { IgxGridSelectionService, IgxGridCRUDService } from '../../core/grid-selection';
88
import { HammerGesturesManager } from '../../core/touch';
9+
import { PlatformUtil } from '../../core/utils';
910

1011
@Component({
1112
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -27,9 +28,10 @@ export class IgxHierarchicalGridCellComponent extends IgxGridCellComponent imple
2728
public cdr: ChangeDetectorRef,
2829
private helement: ElementRef,
2930
protected zone: NgZone,
30-
touchManager: HammerGesturesManager
31+
touchManager: HammerGesturesManager,
32+
protected platformUtil: PlatformUtil
3133
) {
32-
super(selectionService, crudService, gridAPI, cdr, helement, zone, touchManager);
34+
super(selectionService, crudService, gridAPI, cdr, helement, zone, touchManager, platformUtil);
3335
// this.hSelection = <IgxHierarchicalSelectionAPIService>selection;
3436
}
3537

projects/igniteui-angular/src/lib/grids/tree-grid/tree-cell.component.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Component, ChangeDetectorRef, ElementRef, ViewChild, Inject,
33
import { IgxGridCellComponent } from '../cell.component';
44
import { IgxTreeGridAPIService } from './tree-grid-api.service';
55
import { GridBaseAPIService } from '../api.service';
6-
import { getNodeSizeViaRange } from '../../core/utils';
6+
import { getNodeSizeViaRange, PlatformUtil } from '../../core/utils';
77
import { DOCUMENT } from '@angular/common';
88
import { IgxGridBaseComponent, IGridDataBindable } from '../grid';
99
import { IgxGridSelectionService, IgxGridCRUDService } from '../../core/grid-selection';
@@ -26,8 +26,9 @@ export class IgxTreeGridCellComponent extends IgxGridCellComponent implements On
2626
element: ElementRef,
2727
protected zone: NgZone,
2828
touchManager: HammerGesturesManager,
29-
@Inject(DOCUMENT) public document) {
30-
super(selectionService, crudService, gridAPI, cdr, element, zone, touchManager);
29+
@Inject(DOCUMENT) public document,
30+
protected platformUtil: PlatformUtil) {
31+
super(selectionService, crudService, gridAPI, cdr, element, zone, touchManager, platformUtil);
3132
this.treeGridAPI = <IgxTreeGridAPIService>gridAPI;
3233
}
3334

0 commit comments

Comments
 (0)