Skip to content

Commit

Permalink
perf(grids): limit cell double tap handler to just iOS #2538
Browse files Browse the repository at this point in the history
  • Loading branch information
damyanpetev committed Sep 17, 2019
1 parent cb0ce2c commit 14de710
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
11 changes: 11 additions & 0 deletions projects/igniteui-angular/src/lib/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ export function isFirefox(): boolean {
return firefoxBrowser;
}

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

/**
* @hidden
*/
Expand Down
12 changes: 8 additions & 4 deletions projects/igniteui-angular/src/lib/grids/cell.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import { IgxSelectionAPIService } from '../core/selection';
import { IgxTextHighlightDirective } from '../directives/text-highlight/text-highlight.directive';
import { GridBaseAPIService } from './api.service';
import { IgxColumnComponent } from './column.component';
import { getNodeSizeViaRange, ROW_COLLAPSE_KEYS, ROW_EXPAND_KEYS, SUPPORTED_KEYS, NAVIGATION_KEYS, isIE, isLeftClick } from '../core/utils';
import {
getNodeSizeViaRange, ROW_COLLAPSE_KEYS, ROW_EXPAND_KEYS, SUPPORTED_KEYS, NAVIGATION_KEYS, isIE, isLeftClick, PlatformUtil
} from '../core/utils';
import { State } from '../services/index';
import { IgxGridBaseComponent, IGridEditEventArgs, IGridDataBindable } from './grid-base.component';
import { IgxGridSelectionService, ISelectionNode, IgxGridCRUDService } from '../core/grid-selection';
Expand Down Expand Up @@ -555,9 +557,11 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
this.nativeElement.addEventListener('compositionend', this.compositionEndHandler);
}
});
this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
cssProps: { } /* don't disable user-select, etc */
} as HammerOptions);
if (PlatformUtil.isIOS()) {
this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
cssProps: { } /* don't disable user-select, etc */
} as HammerOptions);
}
}

/**
Expand Down
11 changes: 10 additions & 1 deletion projects/igniteui-angular/src/lib/grids/grid/cell.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { configureTestSuite } from '../../test-utils/configure-suite';
import { IgxStringFilteringOperand } from '../../data-operations/filtering-condition';
import { SampleTestData } from '../../test-utils/sample-test-data.spec';
import { HammerGesturesManager } from '../../core/touch';
import { PlatformUtil } from '../../core/utils';

const DEBOUNCETIME = 30;

Expand Down Expand Up @@ -186,8 +187,16 @@ describe('IgxGrid - Cell component', () => {
expect(firstCell).toBe(fix.componentInstance.clickedCell);
});

it('Should handle doubletap, trigger onDoubleClick event', () => {
it('Should not attach doubletap handler for non-iOS', () => {
const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener');
spyOn(PlatformUtil, 'isIOS').and.returnValue(false);
const fix = TestBed.createComponent(DefaultGridComponent);
fix.detectChanges();
});

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

Expand Down

0 comments on commit 14de710

Please sign in to comment.