Skip to content

Commit 3f7f109

Browse files
authored
Merge pull request #5816 from IgniteUI/dpetev/ios-grid-edit-detect-7.3
perf(grids): limit cell double tap handler to just iOS
2 parents ebb9f93 + 89d01d7 commit 3f7f109

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

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

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

229+
/**
230+
* @hidden
231+
* TODO: make injectable, check isPlatformBrowser()
232+
*/
233+
export function isIOS(): boolean {
234+
const iosBrowser = typeof window !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window);
235+
return iosBrowser;
236+
}
237+
229238
/**
230239
* @hidden
231240
*/

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import { IgxSelectionAPIService } from '../core/selection';
1818
import { IgxTextHighlightDirective } from '../directives/text-highlight/text-highlight.directive';
1919
import { GridBaseAPIService } from './api.service';
2020
import { IgxColumnComponent } from './column.component';
21-
import { getNodeSizeViaRange, ROW_COLLAPSE_KEYS, ROW_EXPAND_KEYS, SUPPORTED_KEYS, NAVIGATION_KEYS, isIE, isLeftClick } from '../core/utils';
21+
import {
22+
getNodeSizeViaRange, ROW_COLLAPSE_KEYS, ROW_EXPAND_KEYS, SUPPORTED_KEYS, NAVIGATION_KEYS, isIE, isLeftClick, isIOS
23+
} from '../core/utils';
2224
import { State } from '../services/index';
2325
import { IgxGridBaseComponent, IGridEditEventArgs, IGridDataBindable } from './grid-base.component';
2426
import { IgxGridSelectionService, ISelectionNode, IgxGridCRUDService } from '../core/grid-selection';
@@ -563,9 +565,11 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
563565
this.nativeElement.addEventListener('focusout', this.focusOut);
564566
}
565567
});
566-
this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
567-
cssProps: { } /* don't disable user-select, etc */
568-
} as HammerOptions);
568+
if (isIOS()) {
569+
this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
570+
cssProps: { } /* don't disable user-select, etc */
571+
} as HammerOptions);
572+
}
569573
}
570574

571575
/**

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { configureTestSuite } from '../../test-utils/configure-suite';
99
import { IgxStringFilteringOperand, IgxNumberFilteringOperand } from '../../data-operations/filtering-condition';
1010
import { SampleTestData } from '../../test-utils/sample-test-data.spec';
1111
import { HammerGesturesManager } from '../../core/touch';
12+
import * as utils from '../../core/utils';
1213

1314
const DEBOUNCETIME = 30;
1415

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

189-
it('Should handle doubletap, trigger onDoubleClick event', () => {
190+
it('Should not attach doubletap handler for non-iOS', () => {
190191
const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener');
192+
spyOn(utils, 'isIOS').and.returnValue(false);
193+
const fix = TestBed.createComponent(DefaultGridComponent);
194+
fix.detectChanges();
195+
});
196+
197+
it('Should handle doubletap on iOS, trigger onDoubleClick event', () => {
198+
const addListenerSpy = spyOn(HammerGesturesManager.prototype, 'addEventListener');
199+
spyOn(utils, 'isIOS').and.returnValue(true);
191200
const fix = TestBed.createComponent(DefaultGridComponent);
192201
fix.detectChanges();
193202

0 commit comments

Comments
 (0)