From ceccd024ed696cc02f600566f8ff23d638dc8956 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Thu, 1 Feb 2018 22:40:02 +0100 Subject: [PATCH] fix(status-tap): using ion-scroll API --- packages/core/src/components.d.ts | 30 +++++++++++++ packages/core/src/components/app/app.tsx | 13 +++--- .../core/src/components/status-tap/readme.md | 16 +++++++ .../src/components/status-tap/status-tap.tsx | 42 +++++++++---------- packages/core/stencil.config.js | 1 + 5 files changed, 73 insertions(+), 29 deletions(-) create mode 100644 packages/core/src/components/status-tap/readme.md diff --git a/packages/core/src/components.d.ts b/packages/core/src/components.d.ts index 9d8b854a6d..5c894c8d7a 100644 --- a/packages/core/src/components.d.ts +++ b/packages/core/src/components.d.ts @@ -2805,6 +2805,36 @@ declare global { } +import { + StatusTap as IonStatusTap +} from './components/status-tap/status-tap'; + +declare global { + interface HTMLIonStatusTapElement extends IonStatusTap, HTMLElement { + } + var HTMLIonStatusTapElement: { + prototype: HTMLIonStatusTapElement; + new (): HTMLIonStatusTapElement; + }; + interface HTMLElementTagNameMap { + "ion-status-tap": HTMLIonStatusTapElement; + } + interface ElementTagNameMap { + "ion-status-tap": HTMLIonStatusTapElement; + } + namespace JSX { + interface IntrinsicElements { + "ion-status-tap": JSXElements.IonStatusTapAttributes; + } + } + namespace JSXElements { + export interface IonStatusTapAttributes extends HTMLAttributes { + + } + } +} + + import { TabButton as IonTabButton } from './components/tab-button/tab-button'; diff --git a/packages/core/src/components/app/app.tsx b/packages/core/src/components/app/app.tsx index 6dd3d86b46..67d6c0d87e 100644 --- a/packages/core/src/components/app/app.tsx +++ b/packages/core/src/components/app/app.tsx @@ -131,12 +131,13 @@ export class App { } render() { - const dom = [, ]; - if (this.useRouter) { - - // dom.push(); - } - return dom; + const isDevice = true; + return [ + isDevice && , + isDevice && , + // + + ]; } } diff --git a/packages/core/src/components/status-tap/readme.md b/packages/core/src/components/status-tap/readme.md new file mode 100644 index 0000000000..7d5a3427d8 --- /dev/null +++ b/packages/core/src/components/status-tap/readme.md @@ -0,0 +1,16 @@ +# ion-status-tap + + + + + + +## Methods + +#### mockTap() + + + +---------------------------------------------- + +*Built by [StencilJS](https://stenciljs.com/)* diff --git a/packages/core/src/components/status-tap/status-tap.tsx b/packages/core/src/components/status-tap/status-tap.tsx index cb6c60dbe6..ad475f0a62 100644 --- a/packages/core/src/components/status-tap/status-tap.tsx +++ b/packages/core/src/components/status-tap/status-tap.tsx @@ -1,7 +1,6 @@ import { Component, Listen, Method, Prop } from '@stencil/core'; import { DomController } from '../..'; -import { domControllerAsync } from '../../utils/helpers'; @Component({ tag: 'ion-status-tap' @@ -10,33 +9,30 @@ export class StatusTap { @Prop({ context: 'dom' }) dom: DomController; + @Prop() duration = 300; + @Listen('window:statusTap') statusTap() { - handleTap(this); + this.tap(); } @Method() mockTap() { - return handleTap(this); + this.tap(); + } + + private tap() { + this.dom.read(() => { + const width = window.innerWidth; + const height = window.innerWidth; + const el = document.elementFromPoint(width / 2, height / 2); + if (!el) { + return; + } + const scroll = el.closest('ion-scroll') as HTMLIonScrollElement; + (scroll as any).componentOnReady().then(() => { + this.dom.write(() => scroll.scrollToTop(this.duration)); + }); + }); } } - -export function handleTap(tap: StatusTap): Promise { - let width = 0; - let height = 0; - return domControllerAsync(tap.dom.read, () => { - width = window.innerWidth; - height = window.innerHeight; - }).then(() => { - const element = document.elementFromPoint(width / 2, height / 2); - if (!element) { - return; - } - const content = element.closest('.scroll-content'); - if (!content) { - return; - } - - throw new Error('Manu going to take over here'); - }); -} diff --git a/packages/core/stencil.config.js b/packages/core/stencil.config.js index ae174500c9..7ee90fb562 100644 --- a/packages/core/stencil.config.js +++ b/packages/core/stencil.config.js @@ -41,6 +41,7 @@ exports.config = { { components: ['ion-tabs', 'ion-tab', 'ion-tabbar', 'ion-tab-button'] }, { components: ['ion-toggle'] }, { components: ['ion-toast', 'ion-toast-controller'] }, + { components: ['ion-tap-click', 'ion-status-tap'] }, ], collections: [ 'ionicons'