diff --git a/packages/core/src/components/action-sheet/action-sheet.tsx b/packages/core/src/components/action-sheet/action-sheet.tsx index f821d08170..08d97fa074 100644 --- a/packages/core/src/components/action-sheet/action-sheet.tsx +++ b/packages/core/src/components/action-sheet/action-sheet.tsx @@ -109,75 +109,6 @@ export class ActionSheet { */ @Event() ionActionSheetDidUnload: EventEmitter; - /** - * Present the action sheet overlay after it has been created. - */ - @Method() - present() { - if (this.animation) { - this.animation.destroy(); - this.animation = null; - } - this.ionActionSheetWillPresent.emit(); - - this.el.style.zIndex = `${20000 + this.actionSheetId}`; - - // get the user's animation fn if one was provided - const animationBuilder = this.enterAnimation || this.config.get('actionSheetEnter', this.mode === 'ios' ? iosEnterAnimation : mdEnterAnimation); - - // build the animation and kick it off - return this.animationCtrl.create(animationBuilder, this.el).then(animation => { - - this.animation = animation; - - // Check if prop animate is false or if the config for animate is defined/false - if (!this.willAnimate || (isDef(this.config.get('willAnimate')) && this.config.get('willAnimate') === false)) { - // if the duration is 0, it won't actually animate I don't think - // TODO - validate this - this.animation = animation.duration(0); - } - return playAnimationAsync(animation); - }).then((animation) => { - animation.destroy(); - this.ionActionSheetDidPresent.emit(); - }); - } - - /** - * Dismiss the action sheet overlay after it has been presented. - */ - @Method() - dismiss(data?: any, role?: string) { - if (this.animation) { - this.animation.destroy(); - this.animation = null; - } - this.ionActionSheetWillDismiss.emit({ - data, - role - }); - const animationBuilder = this.leaveAnimation || this.config.get('actionSheetLeave', this.mode === 'ios' ? iosLeaveAnimation : mdLeaveAnimation); - - return this.animationCtrl.create(animationBuilder, this.el).then(animation => { - this.animation = animation; - - if (!this.willAnimate || (isDef(this.config.get('willAnimate')) && this.config.get('willAnimate') === false)) { - this.animation = animation.duration(0); - } - - return playAnimationAsync(animation); - }).then((animation) => { - animation.destroy(); - this.ionActionSheetDidDismiss.emit({ - data, - role - }); - }).then(() => { - return domControllerAsync(this.dom.write, () => { - this.el.parentNode.removeChild(this.el); - }); - }); - } componentDidLoad() { this.ionActionSheetDidLoad.emit(); @@ -200,6 +131,61 @@ export class ActionSheet { this.dismiss(); } + /** + * Present the action sheet overlay after it has been created. + */ + @Method() + present() { + this.ionActionSheetWillPresent.emit(); + + this.el.style.zIndex = `${20000 + this.actionSheetId}`; + + // get the user's animation fn if one was provided + const animationBuilder = this.enterAnimation || this.config.get('actionSheetEnter', this.mode === 'ios' ? iosEnterAnimation : mdEnterAnimation); + + // build the animation and kick it off + return this.playAnimation(animationBuilder).then(() => { + this.ionActionSheetDidPresent.emit(); + }); + } + + /** + * Dismiss the action sheet overlay after it has been presented. + */ + @Method() + dismiss(data?: any, role?: string) { + this.ionActionSheetWillDismiss.emit({data, role}); + + const animationBuilder = this.leaveAnimation || this.config.get('actionSheetLeave', this.mode === 'ios' ? iosLeaveAnimation : mdLeaveAnimation); + return this.playAnimation(animationBuilder).then(() => { + this.ionActionSheetDidDismiss.emit({data, role}); + return domControllerAsync(this.dom.write, () => { + this.el.parentNode.removeChild(this.el); + }); + }); + } + + private playAnimation(animationBuilder: AnimationBuilder) { + if (this.animation) { + this.animation.destroy(); + this.animation = null; + } + + return this.animationCtrl.create(animationBuilder, this.el).then(animation => { + this.animation = animation; + // Check if prop animate is false or if the config for animate is defined/false + if (!this.willAnimate || (isDef(this.config.get('willAnimate')) && this.config.get('willAnimate') === false)) { + // if the duration is 0, it won't actually animate I don't think + // TODO - validate this + this.animation = animation.duration(0); + } + return playAnimationAsync(animation); + }).then((animation) => { + animation.destroy(); + this.animation = null; + }); + } + protected buttonClick(button: ActionSheetButton) { let shouldDismiss = true; if (button.handler) { diff --git a/packages/core/src/components/alert/alert.tsx b/packages/core/src/components/alert/alert.tsx index 7991b081c9..5b6e4c3bda 100644 --- a/packages/core/src/components/alert/alert.tsx +++ b/packages/core/src/components/alert/alert.tsx @@ -1,4 +1,4 @@ -import { Component, CssClassMap, Element, Event, EventEmitter, Method, Prop, Listen } from '@stencil/core'; +import { Component, CssClassMap, Element, Event, EventEmitter, Listen, Method, Prop } from '@stencil/core'; import { Animation, AnimationBuilder, AnimationController, Config, DomController, OverlayDismissEvent, OverlayDismissEventDetail } from '../../index'; import { domControllerAsync, playAnimationAsync } from '../../utils/helpers'; @@ -123,75 +123,6 @@ export class Alert { */ @Event() ionAlertDidUnload: EventEmitter; - /** - * Present the alert overlay after it has been created. - */ - @Method() - present() { - if (this.animation) { - this.animation.destroy(); - this.animation = null; - } - this.ionAlertWillPresent.emit(); - - this.el.style.zIndex = `${20000 + this.alertId}`; - - // get the user's animation fn if one was provided - const animationBuilder = this.enterAnimation || this.config.get('alertEnter', this.mode === 'ios' ? iosEnterAnimation : mdEnterAnimation); - - // build the animation and kick it off - return this.animationCtrl.create(animationBuilder, this.el).then(animation => { - this.animation = animation; - if (!this.willAnimate) { - // if the duration is 0, it won't actually animate I don't think - // TODO - validate this - this.animation = animation.duration(0); - } - return playAnimationAsync(animation); - }).then((animation) => { - animation.destroy(); - const firstInput = this.el.querySelector('[tabindex]') as HTMLElement; - if (firstInput) { - firstInput.focus(); - } - - this.ionAlertDidPresent.emit(); - }); - } - - /** - * Dismiss the alert overlay after it has been presented. - */ - @Method() - dismiss(data?: any, role?: string) { - if (this.animation) { - this.animation.destroy(); - this.animation = null; - } - this.ionAlertWillDismiss.emit({ - data: data, - role: role - }); - - // get the user's animation fn if one was provided - const animationBuilder = this.leaveAnimation || this.config.get('alertLeave', this.mode === 'ios' ? iosLeaveAnimation : mdLeaveAnimation); - - return this.animationCtrl.create(animationBuilder, this.el).then(animation => { - this.animation = animation; - return playAnimationAsync(animation); - }).then((animation) => { - animation.destroy(); - this.ionAlertDidDismiss.emit({ - data: data, - role: role - }); - }).then(() => { - return domControllerAsync(this.dom.write, () => { - this.el.parentNode.removeChild(this.el); - }); - }); - } - componentDidLoad() { this.ionAlertDidLoad.emit(); } @@ -209,7 +140,46 @@ export class Alert { this.dismiss(null, BACKDROP); } - rbClick(inputIndex: number) { + /** + * Present the alert overlay after it has been created. + */ + @Method() + present() { + this.ionAlertWillPresent.emit(); + + this.el.style.zIndex = `${20000 + this.alertId}`; + + // get the user's animation fn if one was provided + const animationBuilder = this.enterAnimation || this.config.get('alertEnter', this.mode === 'ios' ? iosEnterAnimation : mdEnterAnimation); + + // build the animation and kick it off + return this.playAnimation(animationBuilder).then(() => { + const firstInput = this.el.querySelector('[tabindex]') as HTMLElement; + if (firstInput) { + firstInput.focus(); + } + this.ionAlertDidPresent.emit(); + }); + } + + /** + * Dismiss the alert overlay after it has been presented. + */ + @Method() + dismiss(data?: any, role?: string) { + this.ionAlertWillDismiss.emit({data, role}); + + // get the user's animation fn if one was provided + const animationBuilder = this.leaveAnimation || this.config.get('alertLeave', this.mode === 'ios' ? iosLeaveAnimation : mdLeaveAnimation); + + return this.playAnimation(animationBuilder).then(() => { + return domControllerAsync(this.dom.write, () => { + this.el.parentNode.removeChild(this.el); + }); + }); + } + + private rbClick(inputIndex: number) { this.inputs = this.inputs.map((input, index) => { input.checked = (inputIndex === index); return input; @@ -223,7 +193,7 @@ export class Alert { } } - cbClick(inputIndex: number) { + private cbClick(inputIndex: number) { this.inputs = this.inputs.map((input, index) => { if (inputIndex === index) { input.checked = !input.checked; @@ -237,7 +207,7 @@ export class Alert { } } - buttonClick(button: any) { + private buttonClick(button: any) { let shouldDismiss = true; if (button.handler) { @@ -254,7 +224,7 @@ export class Alert { } } - getValues(): any { + private getValues(): any { if (this.inputType === 'radio') { // this is an alert with radio buttons (single value select) // return the one value which is checked, otherwise undefined @@ -287,8 +257,27 @@ export class Alert { return values; } + private playAnimation(animationBuilder: AnimationBuilder) { + if (this.animation) { + this.animation.destroy(); + this.animation = null; + } - renderCheckbox(inputs: AlertInput[]) { + return this.animationCtrl.create(animationBuilder, this.el).then(animation => { + this.animation = animation; + if (!this.willAnimate) { + // if the duration is 0, it won't actually animate I don't think + animation.duration(0); + } + return playAnimationAsync(animation); + }).then(animation => { + animation.destroy(); + this.animation = null; + }); + } + + + private renderCheckbox(inputs: AlertInput[]) { if (inputs.length === 0) return null; return ( @@ -307,7 +296,7 @@ export class Alert { ); } - renderRadio(inputs: AlertInput[]) { + private renderRadio(inputs: AlertInput[]) { if (inputs.length === 0) return null; return ( @@ -326,7 +315,7 @@ export class Alert { ); } - renderInput(inputs: AlertInput[]) { + private renderInput(inputs: AlertInput[]) { if (inputs.length === 0) return null; return ( diff --git a/packages/core/src/components/app/app.tsx b/packages/core/src/components/app/app.tsx index d4a7039a7c..b8f9d43a96 100644 --- a/packages/core/src/components/app/app.tsx +++ b/packages/core/src/components/app/app.tsx @@ -133,7 +133,7 @@ export class App { } @Method() - getNavByIdOrName(nameOrId: number | string): PublicNav { + getNavByIdOrName(nameOrId: number | string): PublicNav|null { const navs = Array.from(rootNavs.values()); for (const navContainer of navs) { const match = getNavByIdOrNameImpl(navContainer, nameOrId); @@ -222,12 +222,12 @@ export class App { } @Listen('document:paused') - appResume(): void { + appResume(): null { return null; } @Listen('document:resume') - appPaused(): void { + appPaused(): null { return null; } diff --git a/packages/core/src/components/backdrop/backdrop.tsx b/packages/core/src/components/backdrop/backdrop.tsx index c9d998650f..d9db269fd5 100644 --- a/packages/core/src/components/backdrop/backdrop.tsx +++ b/packages/core/src/components/backdrop/backdrop.tsx @@ -1,4 +1,4 @@ -import { Component, Listen, EventEmitter, Event, Prop } from '@stencil/core'; +import { Component, Event, EventEmitter, Listen, Prop } from '@stencil/core'; import { now } from '../../utils/helpers'; @Component({ @@ -29,13 +29,13 @@ export class Backdrop { @Listen('mousedown', {passive: false, capture: true}) protected onMouseDown(ev: TouchEvent) { - if(this.lastClick < now(ev) - 2500) { + if (this.lastClick < now(ev) - 2500) { this.emitTap(ev); } } private emitTap(ev: Event) { - if(this.stopPropagation) { + if (this.stopPropagation) { ev.preventDefault(); ev.stopPropagation(); } diff --git a/packages/core/src/components/gesture-controller/gesture-controller.ts b/packages/core/src/components/gesture-controller/gesture-controller.ts index 52ddc9b2e6..a1b9b5b7be 100644 --- a/packages/core/src/components/gesture-controller/gesture-controller.ts +++ b/packages/core/src/components/gesture-controller/gesture-controller.ts @@ -1,4 +1,4 @@ -import { Component, Method, EventEmitter, Event } from "@stencil/core"; +import { Component, Event, EventEmitter, Method } from '@stencil/core'; @Component({ @@ -82,21 +82,11 @@ export class GestureController { } disableScroll(id: number) { - // let isEnabled = !this.isScrollDisabled(); this.disabledScroll.add(id); - // if (this._app && isEnabled && this.isScrollDisabled()) { - // console.debug('GestureController: Disabling scrolling'); - // this._app._setDisableScroll(true); - // } } enableScroll(id: number) { - // let isDisabled = this.isScrollDisabled(); this.disabledScroll.delete(id); - // if (this._app && isDisabled && !this.isScrollDisabled()) { - // console.debug('GestureController: Enabling scrolling'); - // this._app._setDisableScroll(false); - // } } canStart(gestureName: string): boolean { diff --git a/packages/core/src/components/gesture/gesture.tsx b/packages/core/src/components/gesture/gesture.tsx index 5b750f4811..8b97a43184 100644 --- a/packages/core/src/components/gesture/gesture.tsx +++ b/packages/core/src/components/gesture/gesture.tsx @@ -1,6 +1,6 @@ import { Component, Event, EventEmitter, EventListenerEnable, Listen, Prop, Watch } from '@stencil/core'; import { ElementRef, assert, now, updateDetail } from '../../utils/helpers'; -import { BlockerDelegate, GestureDelegate, BlockerConfig, BLOCK_ALL } from '../gesture-controller/gesture-controller'; +import { BLOCK_ALL, BlockerConfig, BlockerDelegate, GestureDelegate } from '../gesture-controller/gesture-controller'; import { DomController } from '../../index'; import { PanRecognizer } from './recognizers'; @@ -348,6 +348,7 @@ export class Gesture { // END ************************* @Listen('touchcancel', { passive: true, enabled: false }) + @Listen('touchend', { passive: true, enabled: false }) onTouchCancel(ev: TouchEvent) { this.lastTouch = this.detail.timeStamp = now(ev); @@ -355,16 +356,6 @@ export class Gesture { this.enableTouch(false); } - - @Listen('touchend', { passive: true, enabled: false }) - onTouchEnd(ev: TouchEvent) { - this.lastTouch = this.detail.timeStamp = now(ev); - - this.pointerUp(ev); - this.enableTouch(false); - } - - @Listen('document:mouseup', { passive: true, enabled: false }) onMouseUp(ev: TouchEvent) { const timeStamp = now(ev); diff --git a/packages/core/src/components/hide-when/hide-when.tsx b/packages/core/src/components/hide-when/hide-when.tsx index 2cf0fec92e..358f11b79b 100644 --- a/packages/core/src/components/hide-when/hide-when.tsx +++ b/packages/core/src/components/hide-when/hide-when.tsx @@ -40,7 +40,7 @@ export class HideWhen implements DisplayWhen { } render() { - return + return ; } } diff --git a/packages/core/src/components/infinite-scroll/infinite-scroll.tsx b/packages/core/src/components/infinite-scroll/infinite-scroll.tsx index e5267766eb..82e4638272 100644 --- a/packages/core/src/components/infinite-scroll/infinite-scroll.tsx +++ b/packages/core/src/components/infinite-scroll/infinite-scroll.tsx @@ -85,7 +85,7 @@ export class InfiniteScroll { componentWillLoad() { const scrollEl = this.el.closest('ion-scroll'); return scrollEl.componentOnReady().then((el) => { - this.scrollEl = el as HTMLIonScrollElement; + this.scrollEl = el; }); } diff --git a/packages/core/src/components/input/input-device-utils.ts b/packages/core/src/components/input/input-device-utils.ts index aeae6c2a7b..66a428e1f5 100644 --- a/packages/core/src/components/input/input-device-utils.ts +++ b/packages/core/src/components/input/input-device-utils.ts @@ -1,6 +1,6 @@ -import { assert } from "../../utils/helpers"; -import { CSS_PROP } from "../animation-controller/constants"; -import { App } from "../.."; +import { assert } from '../../utils/helpers'; +import { CSS_PROP } from '../animation-controller/constants'; +import { App } from '../..'; const SCROLL_DATA_MAP = new WeakMap(); const SCROLL_ASSIST_SPEED = 0.3; @@ -81,21 +81,27 @@ export function enableScrollPadding(_componentEl: HTMLElement, inputEl: HTMLElem return () => { inputEl.removeEventListener('focus', onFocus); - } + }; } export function enableScrollMove( componentEl: HTMLElement, + inputEl: HTMLElement, contentEl: HTMLIonContentElement, keyboardHeight: number ) { console.debug('Input: enableAutoScroll'); - this.ionFocus.subscribe(() => { - const scrollData = getScrollData(componentEl, contentEl, keyboardHeight) + const onFocus = () => { + const scrollData = getScrollData(componentEl, contentEl, keyboardHeight); if (Math.abs(scrollData.scrollAmount) > 4) { contentEl.scrollBy(0, scrollData.scrollAmount); } - }); + }; + + inputEl.addEventListener('focus', onFocus); + return () => { + inputEl.removeEventListener('focus', onFocus); + }; } const SKIP_BLURRING = ['INPUT', 'TEXTAREA', 'ION-INPUT', 'ION-TEXTAREA']; @@ -150,7 +156,7 @@ export function enableInputBlurring(app: App) { return () => { document.removeEventListener('focusin', onFocusin, true); document.removeEventListener('touchend', onTouchend, false); - } + }; } export function enableHideCaretOnScroll(componentEl: HTMLElement, inputEl: HTMLInputElement, scrollEl: HTMLIonScrollElement) { @@ -158,7 +164,7 @@ export function enableHideCaretOnScroll(componentEl: HTMLElement, inputEl: HTMLI console.debug('Input: enableHideCaretOnScroll'); function scrollHideCaret(shouldHideCaret: boolean) { - if(isFocused(inputEl)) { + if (isFocused(inputEl)) { relocateInput(componentEl, inputEl, shouldHideCaret); } } @@ -168,12 +174,12 @@ export function enableHideCaretOnScroll(componentEl: HTMLElement, inputEl: HTMLI const showCaret = () => scrollHideCaret(false); scrollEl.addEventListener('ionScrollStart', hideCaret); - scrollEl.addEventListener('ionScrollEnd',showCaret); + scrollEl.addEventListener('ionScrollEnd', showCaret); inputEl.addEventListener('blur', onBlur); return () => { scrollEl.removeEventListener('ionScrollStart', hideCaret); - scrollEl.removeEventListener('ionScrollEnd',showCaret); + scrollEl.removeEventListener('ionScrollEnd', showCaret); inputEl.addEventListener('ionBlur', onBlur); }; } @@ -196,11 +202,13 @@ function cloneInputComponent(componentEle: HTMLElement, nativeInputEle: HTMLInpu // Make sure we kill all the clones before creating new ones // It is a defensive, removeClone() should do nothing // removeClone(plt, srcComponentEle, srcNativeInputEle); - assert(componentEle.parentElement.querySelector('.cloned-input') === null, 'leaked cloned input'); // given a native or