Skip to content

Commit cd309bf

Browse files
authored
Merge pull request #5817 from IgniteUI/dpetev/ios-grid-edit-detect-8.1
perf(grids): limit cell double tap handler to just iOS
2 parents cb0ce2c + 14de710 commit cd309bf

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
@@ -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, PlatformUtil
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';
@@ -555,9 +557,11 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
555557
this.nativeElement.addEventListener('compositionend', this.compositionEndHandler);
556558
}
557559
});
558-
this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
559-
cssProps: { } /* don't disable user-select, etc */
560-
} as HammerOptions);
560+
if (PlatformUtil.isIOS()) {
561+
this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
562+
cssProps: { } /* don't disable user-select, etc */
563+
} as HammerOptions);
564+
}
561565
}
562566

563567
/**

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 } from '../../data-operations/filtering-condition';
1010
import { SampleTestData } from '../../test-utils/sample-test-data.spec';
1111
import { HammerGesturesManager } from '../../core/touch';
12+
import { PlatformUtil } 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(PlatformUtil, '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(PlatformUtil, 'isIOS').and.returnValue(true);
191200
const fix = TestBed.createComponent(DefaultGridComponent);
192201
fix.detectChanges();
193202

0 commit comments

Comments
 (0)