Skip to content

Commit 6562740

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

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
@@ -182,20 +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-
spyOnProperty(PlatformUtil.prototype, '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);
188191
expect(addListenerSpy).not.toHaveBeenCalled();
192+
193+
platformUtil.isIOS = oldIsIOS;
189194
});
190195

191196
it('Should handle doubletap on iOS, trigger onDoubleClick event', () => {
192197
const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener');
193-
spyOnProperty(PlatformUtil.prototype, 'isIOS').and.returnValue(true);
198+
const platformUtil: PlatformUtil = TestBed.get(PlatformUtil);
199+
const oldIsIOS = platformUtil.isIOS;
200+
platformUtil.isIOS = true;
194201
const fix = TestBed.createComponent(DefaultGridComponent);
195202
fix.detectChanges();
196203

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

201207
// should attach 'doubletap'
@@ -218,6 +224,8 @@ describe('IgxGrid - Cell component #grid', () => {
218224
expect(event.preventDefault).toHaveBeenCalled();
219225
expect(grid.onDoubleClick.emit).toHaveBeenCalledWith(args);
220226
expect(firstCell).toBe(fix.componentInstance.clickedCell);
227+
228+
platformUtil.isIOS = oldIsIOS;
221229
});
222230

223231
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
@@ -621,7 +621,7 @@ export class IgxNavigationDrawerComponent implements
621621
* Sets the drawer width.
622622
*/
623623
private setDrawerWidth(width: string) {
624-
if (this.platformUtil.isPlatformBrowser) {
624+
if (this.platformUtil.isBrowser) {
625625
requestAnimationFrame(() => {
626626
if (this.drawer) {
627627
this.renderer.setElementStyle(this.drawer, 'width', width);
@@ -655,7 +655,7 @@ export class IgxNavigationDrawerComponent implements
655655
this._touchManager.addGlobalEventListener('document', 'panmove', this.pan);
656656
this._touchManager.addGlobalEventListener('document', 'panend', this.panEnd);
657657
}
658-
if (!this._resizeObserver && this.platformUtil.isPlatformBrowser) {
658+
if (!this._resizeObserver && this.platformUtil.isBrowser) {
659659
this._resizeObserver = fromEvent(window, 'resize').pipe(debounce(() => interval(150)))
660660
.subscribe((value) => {
661661
this.checkPinThreshold(value);
@@ -673,7 +673,7 @@ export class IgxNavigationDrawerComponent implements
673673
}
674674

675675
private checkPinThreshold = (evt?: Event) => {
676-
if (!this.platformUtil.isPlatformBrowser) {
676+
if (!this.platformUtil.isBrowser) {
677677
return;
678678
}
679679
let windowWidth;

0 commit comments

Comments
 (0)