Skip to content

Commit 57b9405

Browse files
authored
Merge pull request #5818 from IgniteUI/dpetev/ios-grid-edit-detect
perf(grids): limit cell double tap handler to just iOS #2538
2 parents 339ba84 + 806bb59 commit 57b9405

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,17 @@ export function isFirefox(): boolean {
226226
return firefoxBrowser;
227227
}
228228

229+
/**
230+
* @hidden
231+
* TODO: make injectable, check isPlatformBrowser()
232+
*/
233+
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+
}
238+
}
239+
229240
/**
230241
* @hidden
231242
*/

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
} from '@angular/core';
1717
import { IgxTextHighlightDirective } from '../directives/text-highlight/text-highlight.directive';
1818
import { GridBaseAPIService } from './api.service';
19-
import { getNodeSizeViaRange, ROW_COLLAPSE_KEYS, ROW_EXPAND_KEYS, SUPPORTED_KEYS, NAVIGATION_KEYS, isIE, isLeftClick } from '../core/utils';
19+
import {
20+
getNodeSizeViaRange, ROW_COLLAPSE_KEYS, ROW_EXPAND_KEYS, SUPPORTED_KEYS, NAVIGATION_KEYS, isIE, isLeftClick, PlatformUtil
21+
} from '../core/utils';
2022
import { State } from '../services/index';
2123
import { IgxGridBaseComponent, IGridDataBindable } from './grid-base.component';
2224
import { IgxGridSelectionService, ISelectionNode, IgxGridCRUDService } from '../core/grid-selection';
@@ -585,9 +587,11 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
585587
this.nativeElement.addEventListener('compositionend', this.compositionEndHandler);
586588
}
587589
});
588-
this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
589-
cssProps: { } /* don't disable user-select, etc */
590-
} as HammerOptions);
590+
if (PlatformUtil.isIOS()) {
591+
this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
592+
cssProps: { } /* don't disable user-select, etc */
593+
} as HammerOptions);
594+
}
591595
}
592596

593597
/**

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec';
77
import { configureTestSuite } from '../../test-utils/configure-suite';
88
import { SampleTestData } from '../../test-utils/sample-test-data.spec';
99
import { HammerGesturesManager } from '../../core/touch';
10+
import { PlatformUtil } from '../../core/utils';
1011

1112
describe('IgxGrid - Cell component #grid', () => {
1213
configureTestSuite();
@@ -179,8 +180,16 @@ describe('IgxGrid - Cell component #grid', () => {
179180
expect(firstCell).toBe(fix.componentInstance.clickedCell);
180181
});
181182

182-
it('Should handle doubletap, trigger onDoubleClick event', () => {
183+
it('Should not attach doubletap handler for non-iOS', () => {
183184
const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener');
185+
spyOn(PlatformUtil, 'isIOS').and.returnValue(false);
186+
const fix = TestBed.createComponent(DefaultGridComponent);
187+
fix.detectChanges();
188+
});
189+
190+
it('Should handle doubletap on iOS, trigger onDoubleClick event', () => {
191+
const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener');
192+
spyOn(PlatformUtil, 'isIOS').and.returnValue(true);
184193
const fix = TestBed.createComponent(DefaultGridComponent);
185194
fix.detectChanges();
186195

0 commit comments

Comments
 (0)