Skip to content

Commit 43bf838

Browse files
committed
chore(nav-drawer): change isPlatform and isIOS to public fields
1 parent d5a6297 commit 43bf838

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class HammerGesturesManager {
2121
private _hammerManagers: Array<{ element: EventTarget, manager: HammerManager; }> = [];
2222

2323
constructor(private _zone: NgZone, @Inject(DOCUMENT) private doc: any, private platformUtil: PlatformUtil) {
24-
this.platformBrowser = this.platformUtil.isPlatformBrowser;
24+
this.platformBrowser = this.platformUtil.isBrowser;
2525
if (this.platformBrowser) {
2626
this.hammerOptions = {
2727
// D.P. #447 Force TouchInput due to PointerEventInput bug (https://github.com/hammerjs/hammer.js/issues/1065)

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,11 @@ export function isFirefox(): boolean {
234234
*/
235235
@Injectable({ providedIn: 'root' })
236236
export class PlatformUtil {
237-
private platformBrowser: boolean;
237+
public isBrowser: boolean = isPlatformBrowser(this.platformId);
238238

239-
constructor(@Inject(PLATFORM_ID) private platformId: Object) {
240-
this.platformBrowser = isPlatformBrowser(this.platformId);
241-
}
239+
public isIOS = this.isBrowser && /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window);
242240

243-
public get isIOS(): boolean {
244-
const iosBrowser = this.platformBrowser && /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window);
245-
return iosBrowser;
246-
}
247-
248-
public get isPlatformBrowser(): boolean {
249-
return this.platformBrowser;
241+
constructor(@Inject(PLATFORM_ID) private platformId: Object) {
250242
}
251243
}
252244

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +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-
spyOnProperty(PlatformUtil.prototype, '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);
199202
expect(addListenerSpy).not.toHaveBeenCalled();
203+
204+
platformUtil.isIOS = oldIsIOS;
200205
});
201206

202207
it('Should handle doubletap on iOS, trigger onDoubleClick event', () => {
203208
const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener');
204-
spyOnProperty(PlatformUtil.prototype, 'isIOS').and.returnValue(true);
209+
const platformUtil: PlatformUtil = TestBed.get(PlatformUtil);
210+
const oldIsIOS = platformUtil.isIOS;
211+
platformUtil.isIOS = true;
205212
const fix = TestBed.createComponent(DefaultGridComponent);
206213
fix.detectChanges();
207214

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

212218
// should attach 'doubletap'
@@ -229,6 +235,8 @@ describe('IgxGrid - Cell component', () => {
229235
expect(event.preventDefault).toHaveBeenCalled();
230236
expect(grid.onDoubleClick.emit).toHaveBeenCalledWith(args);
231237
expect(firstCell).toBe(fix.componentInstance.clickedCell);
238+
239+
platformUtil.isIOS = oldIsIOS;
232240
});
233241

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

projects/igniteui-angular/src/lib/navigation-drawer/navigation-drawer.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ export class IgxNavigationDrawerComponent implements
603603
* Sets the drawer width.
604604
*/
605605
private setDrawerWidth(width: string) {
606-
if (this.platformUtil.isPlatformBrowser) {
606+
if (this.platformUtil.isBrowser) {
607607
requestAnimationFrame(() => {
608608
if (this.drawer) {
609609
this.renderer.setElementStyle(this.drawer, 'width', width);
@@ -637,7 +637,7 @@ export class IgxNavigationDrawerComponent implements
637637
this._touchManager.addGlobalEventListener('document', 'panmove', this.pan);
638638
this._touchManager.addGlobalEventListener('document', 'panend', this.panEnd);
639639
}
640-
if (!this._resizeObserver && this.platformUtil.isPlatformBrowser) {
640+
if (!this._resizeObserver && this.platformUtil.isBrowser) {
641641
this._resizeObserver = fromEvent(window, 'resize').pipe(debounce(() => interval(150)))
642642
.subscribe((value) => {
643643
this.checkPinThreshold(value);
@@ -655,7 +655,7 @@ export class IgxNavigationDrawerComponent implements
655655
}
656656

657657
private checkPinThreshold = (evt?: Event) => {
658-
if (!this.platformUtil.isPlatformBrowser) {
658+
if (!this.platformUtil.isBrowser) {
659659
return;
660660
}
661661
let windowWidth;

0 commit comments

Comments
 (0)