diff --git a/packages/core/src/components/nav/nav-interface.ts b/packages/core/src/components/nav/nav-interface.ts index a378b8a8b4..1813fcdbf8 100644 --- a/packages/core/src/components/nav/nav-interface.ts +++ b/packages/core/src/components/nav/nav-interface.ts @@ -1,6 +1,6 @@ /* it is very important to keep this interface in sync with ./nav */ -import { NavOptions, ViewController } from '../../index'; +import { NavOptions, PublicViewController } from '../../index'; export interface PublicNav { push(component: any, data?: any, opts?: NavOptions): Promise; @@ -11,14 +11,14 @@ export interface PublicNav { popToRoot(opts?: NavOptions): Promise; popTo(indexOrViewCtrl: any, opts?: NavOptions): Promise; removeIndex(startIndex: number, removeCount?: number, opts?: NavOptions): Promise; - removeView(viewController: ViewController, opts?: NavOptions): Promise; + removeView(viewController: PublicViewController, opts?: NavOptions): Promise; setPages(componentDataPairs: any[], opts?: NavOptions): Promise; - getActive?(): ViewController; - getPrevious?(view?: ViewController): ViewController; - canGoBack?(nav: PublicNav): boolean; + getActive?(): PublicViewController; + getPrevious?(view?: PublicViewController): PublicViewController; + canGoBack?(): boolean; canSwipeBack?(): boolean; - getFirstView?(): ViewController; + getFirstView?(): PublicViewController; element?: HTMLElement; } diff --git a/packages/core/src/components/nav/nav.tsx b/packages/core/src/components/nav/nav.tsx index 608c79ce09..743bd74dbf 100644 --- a/packages/core/src/components/nav/nav.tsx +++ b/packages/core/src/components/nav/nav.tsx @@ -7,6 +7,7 @@ import { NavOptions, NavState, PublicNav, + PublicViewController, RouterEntries, RouterEntry, ViewController @@ -79,7 +80,7 @@ export class Nav implements PublicNav { } } - getViews(): ViewController[] { + getViews(): PublicViewController[] { return getViews(this); } @@ -124,7 +125,7 @@ export class Nav implements PublicNav { } @Method() - removeView(viewController: ViewController, opts?: NavOptions): Promise { + removeView(viewController: PublicViewController, opts?: NavOptions): Promise { return removeViewImpl(this, viewController, opts); } @@ -134,18 +135,18 @@ export class Nav implements PublicNav { } @Method() - getActive(): ViewController { + getActive(): PublicViewController { return getActiveImpl(this); } @Method() - getPrevious(view?: ViewController): ViewController { - return getPreviousImpl(this, view); + getPrevious(view?: PublicViewController): PublicViewController { + return getPreviousImpl(this, view as ViewController); } @Method() - canGoBack(nav: Nav): boolean { - return nav.views && nav.views.length > 0; + canGoBack(): boolean { + return canGoBackImpl(this); } @Method() @@ -154,7 +155,7 @@ export class Nav implements PublicNav { } @Method() - getFirstView(): ViewController { + getFirstView(): PublicViewController { return getFirstView(this); } @@ -278,9 +279,9 @@ export function removeImpl(nav: Nav, startIndex: number, removeCount: number, op }); } -export function removeViewImpl(nav: Nav, viewController: ViewController, opts?: NavOptions) { +export function removeViewImpl(nav: Nav, viewController: PublicViewController, opts?: NavOptions) { return getNavController(nav).then(() => { - return nav.navController.removeView(nav, viewController, opts); + return nav.navController.removeView(nav, viewController as ViewController, opts); }); } @@ -298,6 +299,10 @@ export function getNavController(nav: Nav): Promise { return isReady(nav.navController as any as HTMLElement); } +export function canGoBackImpl(nav: Nav) { + return nav.views && nav.views.length > 0; +} + export function navInitializedImpl(potentialParent: Nav, event: CustomEvent) { if (potentialParent.element !== event.target) { // set the parent on the child nav that dispatched the event diff --git a/packages/core/src/components/tabs/tab.tsx b/packages/core/src/components/tabs/tab.tsx index dfb27e20d7..93fb62760e 100644 --- a/packages/core/src/components/tabs/tab.tsx +++ b/packages/core/src/components/tabs/tab.tsx @@ -1,5 +1,5 @@ import { Component, Element, Event, EventEmitter, Method, Prop, PropDidChange, State } from '@stencil/core'; -import { StencilElement, ViewController } from '../../index'; +import { PublicViewController, StencilElement } from '../../index'; /** * @name Tab @@ -214,7 +214,7 @@ export class Tab { } @Method() - getActive(): Promise { + getActive(): Promise { return this.nav.then(nav => nav && nav.getActive()); } diff --git a/packages/core/src/navigation/nav-controller-functions.ts b/packages/core/src/navigation/nav-controller-functions.ts index bd461fe860..19321ed44f 100644 --- a/packages/core/src/navigation/nav-controller-functions.ts +++ b/packages/core/src/navigation/nav-controller-functions.ts @@ -481,7 +481,7 @@ export function initializeViewBeforeTransition(nav: Nav, ti: TransitionInstructi return startTransaction(ti).then(() => { const viewControllers = convertComponentToViewController(nav, ti); ti.insertViews = viewControllers; - leavingView = ti.nav.getActive(); + leavingView = ti.nav.getActive() as ViewController; enteringView = getEnteringView(ti, ti.nav, leavingView); if (!leavingView && !enteringView) { diff --git a/packages/core/src/navigation/nav-interfaces.ts b/packages/core/src/navigation/nav-interfaces.ts index 4ffb8fbd5a..ca369cc99d 100644 --- a/packages/core/src/navigation/nav-interfaces.ts +++ b/packages/core/src/navigation/nav-interfaces.ts @@ -88,6 +88,7 @@ export interface TransitionBuilder { } export interface PublicViewController { + id?: string; component?: any; instance?: any; element?: HTMLElement; diff --git a/packages/core/src/navigation/nav-utils.ts b/packages/core/src/navigation/nav-utils.ts index c2eb4c083f..d78656176a 100644 --- a/packages/core/src/navigation/nav-utils.ts +++ b/packages/core/src/navigation/nav-utils.ts @@ -40,7 +40,7 @@ export function setZIndex(nav: Nav, enteringView: ViewController, leavingView: V return; } - leavingView = leavingView || nav.getPrevious(enteringView); + leavingView = leavingView || nav.getPrevious(enteringView) as ViewController; if (leavingView && isDef(leavingView.zIndex)) { if (direction === DIRECTION_BACK) { @@ -176,7 +176,7 @@ export function getActiveImpl(nav: Nav): ViewController { export function getPreviousImpl(nav: Nav, viewController: ViewController): ViewController { if (!viewController) { - viewController = nav.getActive(); + viewController = nav.getActive() as ViewController; } return nav.views[nav.views.indexOf(viewController) - 1]; }