From 0c61c2a8c1bb05a1bfa360ab9717cfa873f22b06 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Thu, 17 Nov 2016 17:27:45 +0100 Subject: [PATCH] perf(tapclick): tapPolyfill is only used in UIWebView! - improves drastically the responsiveness in WK and iOS Safari --- src/components/tap-click/tap-click.ts | 5 ++-- src/platform/platform-registry.ts | 35 +++++++++++++++++++++------ src/platform/platform.ts | 7 ++++++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/components/tap-click/tap-click.ts b/src/components/tap-click/tap-click.ts index deec6c22c27..7cba7a89273 100644 --- a/src/components/tap-click/tap-click.ts +++ b/src/components/tap-click/tap-click.ts @@ -32,7 +32,8 @@ export class TapClick { this.activator = new Activator(app, config); } - this.usePolyfill = (config.get('tapPolyfill') === true); + this.usePolyfill = config.getBoolean('tapPolyfill'); + console.debug('Using usePolyfill:', this.usePolyfill); this.events.listen(document, 'click', this.click.bind(this), true); this.pointerEvents = this.events.pointerEvents({ @@ -96,7 +97,7 @@ export class TapClick { if (!this.app.isEnabled()) { preventReason = 'appDisabled'; - } else if (!ev.isIonicTap && this.isDisabledNativeClick()) { + } else if (this.usePolyfill && !ev.isIonicTap && this.isDisabledNativeClick()) { preventReason = 'nativeClick'; } diff --git a/src/platform/platform-registry.ts b/src/platform/platform-registry.ts index 9aa0175cfe2..88dc2ba7005 100644 --- a/src/platform/platform-registry.ts +++ b/src/platform/platform-registry.ts @@ -101,17 +101,17 @@ export const PLATFORM_CONFIGS: {[key: string]: PlatformConfig} = { settings: { autoFocusAssist: 'delay', hoverCSS: false, - inputBlurring: isIOSDevice, - inputCloning: isIOSDevice, + inputBlurring: isIOS, + inputCloning: isIOS, keyboardHeight: 300, mode: 'ios', - scrollAssist: isIOSDevice, + scrollAssist: isIOS, statusbarPadding: !!((window).cordova), - swipeBackEnabled: isIOSDevice, + swipeBackEnabled: isIOS, swipeBackThreshold: 40, - tapPolyfill: isIOSDevice, - virtualScrollEventAssist: !(window.indexedDB), - disableScrollAssist: isIOSDevice, + tapPolyfill: isIOSUI, + virtualScrollEventAssist: isIOSUI, + disableScrollAssist: isIOS, }, isMatch(p: Platform) { return p.isPlatformMatch('ios', ['iphone', 'ipad', 'ipod'], ['windows phone']); @@ -219,7 +219,7 @@ export const PLATFORM_CONFIGS: {[key: string]: PlatformConfig} = { }; -function isIOSDevice(p: Platform) { +function isIOS(p: Platform): boolean { // shortcut function to be reused internally // checks navigator.platform to see if it's an actual iOS device // this does not use the user-agent string because it is often spoofed @@ -227,6 +227,25 @@ function isIOSDevice(p: Platform) { return p.testNavigatorPlatform('iphone|ipad|ipod'); } +function isSafari(p: Platform): boolean { + return p.testUserAgent('Safari'); +} + + +function isWK(): boolean { + return !!window['webkit']; +} + +// Commented out becuase it is not used yet +// function isIOSWK(p: Platform): boolean { +// return isIOS(p) && isWK(); +// } + +function isIOSUI(p: Platform): boolean { + return isIOS(p) && !isWK() && !isSafari(p); +} + + export const PlatformConfigToken = new OpaqueToken('PLTCONFIG'); diff --git a/src/platform/platform.ts b/src/platform/platform.ts index ef02ac1cfdb..417311ea773 100644 --- a/src/platform/platform.ts +++ b/src/platform/platform.ts @@ -560,6 +560,13 @@ export class Platform { } } + testUserAgent(expression: string): boolean { + if (this._ua) { + return this._ua.indexOf(expression) >= 0; + } + return false; + } + /** * @private */