fix(tabs): lazy loading, using ion-nav

This commit is contained in:
Manu Mtz.-Almeida
2017-12-06 19:09:35 +01:00
parent cefbee9ea2
commit 6026339430
14 changed files with 9646 additions and 892 deletions

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@
"dist/"
],
"devDependencies": {
"@stencil/core": "0.0.8-9",
"@stencil/core": "0.0.8-10",
"@stencil/dev-server": "0.0.18-0",
"@stencil/utils": "latest",
"@types/jest": "^21.1.6",

3121
packages/core/src/components.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,6 @@ import {
PublicNav,
PublicViewController,
RouterEntries,
RouterEntry,
ViewController
} from '../../index';
import {
@ -56,17 +55,9 @@ export class Nav implements PublicNav {
this.navId = getNextNavId();
}
@Listen('ionRouteAdded')
routeAdded(ev: CustomEvent) {
this.addRoute(ev.detail);
}
@Listen('ionRouteRemoved')
routeRemoved(ev: CustomEvent) {
this.removeRoute(ev.detail);
}
componentWillLoad() {
this.routes = Array.from(this.element.querySelectorAll('ion-route'))
.map(child => child.getRoute());
this.useRouter = this.config.getBoolean('useRouter', false);
}
@ -169,16 +160,6 @@ export class Nav implements PublicNav {
navInitializedImpl(this, event);
}
@Method()
addRoute(route: RouterEntry) {
this.routes.push(route);
}
@Method()
removeRoute(_: RouterEntry) {
throw 'not implemented';
}
@Method()
getState(): NavState {
assert(this.useRouter, 'routing is disabled');

View File

@ -49,9 +49,6 @@ any
## Methods
#### addRoute()
#### canGoBack()
@ -94,9 +91,6 @@ any
#### removeIndex()
#### removeRoute()
#### removeView()

View File

@ -3,13 +3,13 @@
// Range
// --------------------------------------------------
.item .item-inner {
.item ion-range .item-inner {
overflow: visible;
width: 100%;
}
.item .input-wrapper {
.item ion-range .input-wrapper {
overflow: visible;
flex-direction: column;

View File

@ -39,12 +39,9 @@ string
any
## Events
## Methods
#### ionRouteAdded
#### ionRouteRemoved
#### getRoute()

View File

@ -1,4 +1,4 @@
import { Component, Event, EventEmitter, Prop } from '@stencil/core';
import { Component, Method, Prop } from '@stencil/core';
import { RouterEntry, parseURL } from '../router-controller/router-utils';
@ -11,19 +11,13 @@ export class Route {
@Prop() component: string;
@Prop() props: any = {};
@Event() ionRouteAdded: EventEmitter<RouterEntry>;
@Event() ionRouteRemoved: EventEmitter<string>;
componentDidLoad() {
this.ionRouteAdded.emit({
@Method()
getRoute(): RouterEntry {
return {
path: this.path,
segments: parseURL(this.path),
id: this.component,
props: this.props
});
}
componentDidUnload() {
this.ionRouteRemoved.emit(this.path);
};
}
}

View File

@ -45,6 +45,7 @@ export class RouterController {
if (this.isBlocked()) {
return;
}
debugger;
console.debug('[IN] nav changed -> update URL');
const { stack, pivot } = this.readNavState();
if (pivot) {
@ -91,7 +92,7 @@ export class RouterController {
}
private isHash() {
return this.basePrefix.length > 0 && this.basePrefix[0];
return this.basePrefix.length > 0 && this.basePrefix[0] === '#';
}
private readURL(): string[] {

View File

@ -80,6 +80,16 @@ string
string
#### root
string
#### rootParams
any
#### selected
boolean
@ -132,6 +142,16 @@ string
string
#### root
string
#### rootParams
any
#### selected
boolean
@ -168,6 +188,9 @@ string
#### getNav()
#### getPath()
#### goToRoot()

View File

@ -15,6 +15,16 @@ export class Tab {
@State() init = false;
@State() active = false;
/**
* @input {Page} Set the root page for this tab.
*/
@Prop() root: string;
/**
* @input {object} Any nav-params to pass to the root page of this tab.
*/
@Prop() rootParams: any;
/**
* @input {string} Set the root page for this tab.
*/
@ -83,24 +93,42 @@ export class Tab {
protected componentDidUpdate() {
if (this.init && this.resolveNav) {
const nav = this.el.querySelector('ion-nav') as any as StencilElement;
if (nav) {
nav.componentOnReady(this.resolveNav);
} else {
this.resolveNav(null);
}
this.resolveNav = null;
}
}
@Method()
_setActive(active: boolean): Promise<any> {
if (this.active === active) {
_setActive(shouldActive: boolean): Promise<any> {
if (this.active === shouldActive) {
return Promise.resolve();
}
this.active = active;
this.selected = active;
this.active = shouldActive;
this.selected = shouldActive;
return Promise.resolve();
const needsLifecycle = this.init;
if (shouldActive) {
this.init = true;
}
if (needsLifecycle) {
if (shouldActive) {
// lifecycle didEnter
} else {
// lifecycle didLeave
}
}
return this.nav;
}
@Method()
getPath(): string {
if (this.path != null) {
return this.path;
}
if (this.title) {
return this.title.toLowerCase();
}
return '';
}
@Method()
@ -129,4 +157,11 @@ export class Tab {
}
};
}
render() {
if (this.init) {
return <ion-nav><slot></slot></ion-nav>;
}
return null;
}
}

View File

@ -78,7 +78,7 @@ export class Tabs {
}
@Listen('ionTabbarClick')
@Listen('ionSelect')
// @Listen('ionSelect')
protected tabChange(ev: CustomEvent) {
const selectedTab = ev.detail as HTMLIonTabElement;
this.select(selectedTab);
@ -102,6 +102,7 @@ export class Tabs {
}
selectedTab.selected = true;
console.log('HEY');
// The same selected was selected
// we need to set root in the nested ion-nav if it exist
if (this.selectedTab === selectedTab) {
@ -157,19 +158,21 @@ export class Tabs {
return null;
}
return {
path: selectedTab.path,
path: selectedTab.getPath(),
focusNode: selectedTab
};
}
@Method()
getRoutes(): RouterEntries {
return this.tabs.map(t => {
debugger;
const a = this.tabs.map(t => {
return {
path: t.path,
path: t.getPath(),
id: t
};
});
return a;
}
@Method()

View File

@ -14,27 +14,21 @@
<ion-app>
<ion-tabs>
<ion-tab title="Plain List" icon="star" path="">
<page-tab class="ion-page"></page-tab>
<ion-route path="" component="page-tab"></ion-route>
</ion-tab>
<ion-tab title="Schedule" icon="globe" path="tab2">
<ion-nav root="page-two">
<ion-route path="" component="page-two"></ion-route>
<ion-route path="path/to/page/three" component="page-three"></ion-route>
</ion-nav>
</ion-tab>
<ion-tab title="Stopwatch" icon="logo-facebook" path="tab3">
<ion-nav root="page-three">
<ion-route path="/" component="page-three"></ion-route>
</ion-nav>
</ion-tab>
<ion-tab title="Messages" icon="chatboxes" path="tab4">
<ion-nav root="page-tab">
<ion-route component="page-one"></ion-route>
<ion-route path="paginaaaa-two" component="page-two"></ion-route>
</ion-nav>
</ion-tab>
</ion-tabs>

View File

@ -13,32 +13,26 @@
<ion-app>
<ion-tabs color="primary" translucent>
<ion-tab title="Today" icon="calendar" path="">
<translucent-page-tab class="ion-page"></translucent-page-tab>
<ion-tab title="Today" icon="calendar" path="" root="translucent-page-tab">
<ion-route path="" component="translucent-page-tab"></ion-route>
</ion-tab>
<ion-tab title="Games" icon="planet" path="tab2">
<ion-nav root="page-two">
<ion-tab title="Games" icon="planet" root="page-two">
<ion-route path="" component="page-two"></ion-route>
<ion-route path="path/to/page/three" component="page-three"></ion-route>
</ion-nav>
</ion-tab>
<ion-tab title="Apps" icon="logo-buffer" path="tab3">
<ion-nav root="page-three">
<ion-tab title="Apps" icon="logo-buffer" root="page-three">
<ion-route path="/" component="page-three"></ion-route>
</ion-nav>
</ion-tab>
<ion-tab title="Updates" icon="download" path="tab4" badge="7" badge-style="danger">
<ion-nav root="translucent-page-tab">
<ion-tab title="Updates" icon="download" badge="7" badge-style="danger" root="translucent-page-tab">
<ion-route component="page-one"></ion-route>
<ion-route path="paginaaaa-two" component="page-two"></ion-route>
</ion-nav>
</ion-tab>
<ion-tab title="Search" icon="search" path="tab5">
<translucent-page-tab class="ion-page"></translucent-page-tab>
<ion-tab title="Search" icon="search">
<ion-route path="" component="translucent-page-tab"></ion-route>
</ion-tab>
</ion-tabs>