Skip to content

Commit 2cd874b

Browse files
authored
Merge branch '8.1.x' into mkirova/fix-4520-8.1.x
2 parents 20d2449 + 53603b6 commit 2cd874b

File tree

8 files changed

+195
-131
lines changed

8 files changed

+195
-131
lines changed

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

Lines changed: 32 additions & 18 deletions
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

Lines changed: 39 additions & 8 deletions
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
/**
@@ -278,8 +296,21 @@ export interface CancelableBrowserEventArgs extends CancelableEventArgs {
278296
event?: Event;
279297
}
280298

281-
export const NAVIGATION_KEYS = new Set(['down', 'up', 'left', 'right', 'arrowdown', 'arrowup', 'arrowleft', 'arrowright',
282-
'home', 'end', 'space', 'spacebar', ' ']);
299+
export const NAVIGATION_KEYS = new Set([
300+
'down',
301+
'up',
302+
'left',
303+
'right',
304+
'arrowdown',
305+
'arrowup',
306+
'arrowleft',
307+
'arrowright',
308+
'home',
309+
'end',
310+
'space',
311+
'spacebar',
312+
' '
313+
]);
283314
export const ROW_EXPAND_KEYS = new Set('right down arrowright arrowdown'.split(' '));
284315
export const ROW_COLLAPSE_KEYS = new Set('left up arrowleft arrowup'.split(' '));
285316
export const SUPPORTED_KEYS = new Set([...Array.from(NAVIGATION_KEYS), 'tab', 'enter', 'f2', 'escape', 'esc']);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
538538
public cdr: ChangeDetectorRef,
539539
private element: ElementRef,
540540
protected zone: NgZone,
541-
private touchManager: HammerGesturesManager) { }
541+
private touchManager: HammerGesturesManager,
542+
protected platformUtil: PlatformUtil) { }
542543

543544

544545
/**
@@ -560,7 +561,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
560561
this.nativeElement.addEventListener('compositionend', this.compositionEndHandler);
561562
}
562563
});
563-
if (PlatformUtil.isIOS()) {
564+
if (this.platformUtil.isIOS) {
564565
this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
565566
cssProps: { } /* don't disable user-select, etc */
566567
} as HammerOptions);

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,26 @@ describe('IgxGrid - Cell component', () => {
193193

194194
it('Should not attach doubletap handler for non-iOS', () => {
195195
const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener');
196-
spyOn(PlatformUtil, 'isIOS').and.returnValue(false);
196+
const platformUtil: PlatformUtil = TestBed.get(PlatformUtil);
197+
const oldIsIOS = platformUtil.isIOS;
198+
platformUtil.isIOS = false;
197199
const fix = TestBed.createComponent(DefaultGridComponent);
198200
fix.detectChanges();
201+
// spyOnProperty(PlatformUtil.prototype, 'isIOS').and.returnValue(false);
202+
expect(addListenerSpy).not.toHaveBeenCalled();
203+
204+
platformUtil.isIOS = oldIsIOS;
199205
});
200206

201207
it('Should handle doubletap on iOS, trigger onDoubleClick event', () => {
202208
const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener');
203-
spyOn(PlatformUtil, 'isIOS').and.returnValue(true);
209+
const platformUtil: PlatformUtil = TestBed.get(PlatformUtil);
210+
const oldIsIOS = platformUtil.isIOS;
211+
platformUtil.isIOS = true;
204212
const fix = TestBed.createComponent(DefaultGridComponent);
205213
fix.detectChanges();
206214

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

211218
// should attach 'doubletap'
@@ -228,6 +235,8 @@ describe('IgxGrid - Cell component', () => {
228235
expect(event.preventDefault).toHaveBeenCalled();
229236
expect(grid.onDoubleClick.emit).toHaveBeenCalledWith(args);
230237
expect(firstCell).toBe(fix.componentInstance.clickedCell);
238+
239+
platformUtil.isIOS = oldIsIOS;
231240
});
232241

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

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

Lines changed: 4 additions & 2 deletions
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, selection, cdr, helement, zone, touchManager);
34+
super(selectionService, crudService, gridAPI, selection, cdr, helement, zone, touchManager, platformUtil);
3335
this.hSelection = <IgxHierarchicalSelectionAPIService>selection;
3436
}
3537

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IgxGridCellComponent } from '../cell.component';
33
import { IgxTreeGridAPIService } from './tree-grid-api.service';
44
import { GridBaseAPIService } from '../api.service';
55
import { IgxSelectionAPIService } from '../../core/selection';
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';
@@ -27,8 +27,9 @@ export class IgxTreeGridCellComponent extends IgxGridCellComponent implements On
2727
element: ElementRef,
2828
protected zone: NgZone,
2929
touchManager: HammerGesturesManager,
30-
@Inject(DOCUMENT) public document) {
31-
super(selectionService, crudService, gridAPI, selection, cdr, element, zone, touchManager);
30+
@Inject(DOCUMENT) public document,
31+
protected platformUtil: PlatformUtil) {
32+
super(selectionService, crudService, gridAPI, selection, cdr, element, zone, touchManager, platformUtil);
3233
this.treeGridAPI = <IgxTreeGridAPIService>gridAPI;
3334
}
3435

0 commit comments

Comments
 (0)