mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 22:17:40 +08:00
fix(tabs): lazy loading, using ion-nav
This commit is contained in:
7225
packages/core/package-lock.json
generated
7225
packages/core/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,7 @@
|
|||||||
"dist/"
|
"dist/"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@stencil/core": "0.0.8-9",
|
"@stencil/core": "0.0.8-10",
|
||||||
"@stencil/dev-server": "0.0.18-0",
|
"@stencil/dev-server": "0.0.18-0",
|
||||||
"@stencil/utils": "latest",
|
"@stencil/utils": "latest",
|
||||||
"@types/jest": "^21.1.6",
|
"@types/jest": "^21.1.6",
|
||||||
|
3121
packages/core/src/components.d.ts
vendored
Normal file
3121
packages/core/src/components.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -9,7 +9,6 @@ import {
|
|||||||
PublicNav,
|
PublicNav,
|
||||||
PublicViewController,
|
PublicViewController,
|
||||||
RouterEntries,
|
RouterEntries,
|
||||||
RouterEntry,
|
|
||||||
ViewController
|
ViewController
|
||||||
} from '../../index';
|
} from '../../index';
|
||||||
import {
|
import {
|
||||||
@ -56,17 +55,9 @@ export class Nav implements PublicNav {
|
|||||||
this.navId = getNextNavId();
|
this.navId = getNextNavId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Listen('ionRouteAdded')
|
|
||||||
routeAdded(ev: CustomEvent) {
|
|
||||||
this.addRoute(ev.detail);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Listen('ionRouteRemoved')
|
|
||||||
routeRemoved(ev: CustomEvent) {
|
|
||||||
this.removeRoute(ev.detail);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillLoad() {
|
componentWillLoad() {
|
||||||
|
this.routes = Array.from(this.element.querySelectorAll('ion-route'))
|
||||||
|
.map(child => child.getRoute());
|
||||||
this.useRouter = this.config.getBoolean('useRouter', false);
|
this.useRouter = this.config.getBoolean('useRouter', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,16 +160,6 @@ export class Nav implements PublicNav {
|
|||||||
navInitializedImpl(this, event);
|
navInitializedImpl(this, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Method()
|
|
||||||
addRoute(route: RouterEntry) {
|
|
||||||
this.routes.push(route);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Method()
|
|
||||||
removeRoute(_: RouterEntry) {
|
|
||||||
throw 'not implemented';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Method()
|
@Method()
|
||||||
getState(): NavState {
|
getState(): NavState {
|
||||||
assert(this.useRouter, 'routing is disabled');
|
assert(this.useRouter, 'routing is disabled');
|
||||||
|
@ -49,9 +49,6 @@ any
|
|||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
#### addRoute()
|
|
||||||
|
|
||||||
|
|
||||||
#### canGoBack()
|
#### canGoBack()
|
||||||
|
|
||||||
|
|
||||||
@ -94,9 +91,6 @@ any
|
|||||||
#### removeIndex()
|
#### removeIndex()
|
||||||
|
|
||||||
|
|
||||||
#### removeRoute()
|
|
||||||
|
|
||||||
|
|
||||||
#### removeView()
|
#### removeView()
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,13 +3,13 @@
|
|||||||
// Range
|
// Range
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
|
|
||||||
.item .item-inner {
|
.item ion-range .item-inner {
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.item .input-wrapper {
|
.item ion-range .input-wrapper {
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
|
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
@ -39,12 +39,9 @@ string
|
|||||||
any
|
any
|
||||||
|
|
||||||
|
|
||||||
## Events
|
## Methods
|
||||||
|
|
||||||
#### ionRouteAdded
|
#### getRoute()
|
||||||
|
|
||||||
|
|
||||||
#### ionRouteRemoved
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -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';
|
import { RouterEntry, parseURL } from '../router-controller/router-utils';
|
||||||
|
|
||||||
|
|
||||||
@ -11,19 +11,13 @@ export class Route {
|
|||||||
@Prop() component: string;
|
@Prop() component: string;
|
||||||
@Prop() props: any = {};
|
@Prop() props: any = {};
|
||||||
|
|
||||||
@Event() ionRouteAdded: EventEmitter<RouterEntry>;
|
@Method()
|
||||||
@Event() ionRouteRemoved: EventEmitter<string>;
|
getRoute(): RouterEntry {
|
||||||
|
return {
|
||||||
componentDidLoad() {
|
|
||||||
this.ionRouteAdded.emit({
|
|
||||||
path: this.path,
|
path: this.path,
|
||||||
segments: parseURL(this.path),
|
segments: parseURL(this.path),
|
||||||
id: this.component,
|
id: this.component,
|
||||||
props: this.props
|
props: this.props
|
||||||
});
|
};
|
||||||
}
|
|
||||||
|
|
||||||
componentDidUnload() {
|
|
||||||
this.ionRouteRemoved.emit(this.path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ export class RouterController {
|
|||||||
if (this.isBlocked()) {
|
if (this.isBlocked()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
debugger;
|
||||||
console.debug('[IN] nav changed -> update URL');
|
console.debug('[IN] nav changed -> update URL');
|
||||||
const { stack, pivot } = this.readNavState();
|
const { stack, pivot } = this.readNavState();
|
||||||
if (pivot) {
|
if (pivot) {
|
||||||
@ -91,7 +92,7 @@ export class RouterController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private isHash() {
|
private isHash() {
|
||||||
return this.basePrefix.length > 0 && this.basePrefix[0];
|
return this.basePrefix.length > 0 && this.basePrefix[0] === '#';
|
||||||
}
|
}
|
||||||
|
|
||||||
private readURL(): string[] {
|
private readURL(): string[] {
|
||||||
|
@ -80,6 +80,16 @@ string
|
|||||||
string
|
string
|
||||||
|
|
||||||
|
|
||||||
|
#### root
|
||||||
|
|
||||||
|
string
|
||||||
|
|
||||||
|
|
||||||
|
#### rootParams
|
||||||
|
|
||||||
|
any
|
||||||
|
|
||||||
|
|
||||||
#### selected
|
#### selected
|
||||||
|
|
||||||
boolean
|
boolean
|
||||||
@ -132,6 +142,16 @@ string
|
|||||||
string
|
string
|
||||||
|
|
||||||
|
|
||||||
|
#### root
|
||||||
|
|
||||||
|
string
|
||||||
|
|
||||||
|
|
||||||
|
#### rootParams
|
||||||
|
|
||||||
|
any
|
||||||
|
|
||||||
|
|
||||||
#### selected
|
#### selected
|
||||||
|
|
||||||
boolean
|
boolean
|
||||||
@ -168,6 +188,9 @@ string
|
|||||||
#### getNav()
|
#### getNav()
|
||||||
|
|
||||||
|
|
||||||
|
#### getPath()
|
||||||
|
|
||||||
|
|
||||||
#### goToRoot()
|
#### goToRoot()
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,16 @@ export class Tab {
|
|||||||
@State() init = false;
|
@State() init = false;
|
||||||
@State() active = 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.
|
* @input {string} Set the root page for this tab.
|
||||||
*/
|
*/
|
||||||
@ -83,24 +93,42 @@ export class Tab {
|
|||||||
protected componentDidUpdate() {
|
protected componentDidUpdate() {
|
||||||
if (this.init && this.resolveNav) {
|
if (this.init && this.resolveNav) {
|
||||||
const nav = this.el.querySelector('ion-nav') as any as StencilElement;
|
const nav = this.el.querySelector('ion-nav') as any as StencilElement;
|
||||||
if (nav) {
|
|
||||||
nav.componentOnReady(this.resolveNav);
|
nav.componentOnReady(this.resolveNav);
|
||||||
} else {
|
|
||||||
this.resolveNav(null);
|
|
||||||
}
|
|
||||||
this.resolveNav = null;
|
this.resolveNav = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Method()
|
@Method()
|
||||||
_setActive(active: boolean): Promise<any> {
|
_setActive(shouldActive: boolean): Promise<any> {
|
||||||
if (this.active === active) {
|
if (this.active === shouldActive) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
this.active = active;
|
this.active = shouldActive;
|
||||||
this.selected = active;
|
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()
|
@Method()
|
||||||
@ -129,4 +157,11 @@ export class Tab {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
if (this.init) {
|
||||||
|
return <ion-nav><slot></slot></ion-nav>;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ export class Tabs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Listen('ionTabbarClick')
|
@Listen('ionTabbarClick')
|
||||||
@Listen('ionSelect')
|
// @Listen('ionSelect')
|
||||||
protected tabChange(ev: CustomEvent) {
|
protected tabChange(ev: CustomEvent) {
|
||||||
const selectedTab = ev.detail as HTMLIonTabElement;
|
const selectedTab = ev.detail as HTMLIonTabElement;
|
||||||
this.select(selectedTab);
|
this.select(selectedTab);
|
||||||
@ -102,6 +102,7 @@ export class Tabs {
|
|||||||
}
|
}
|
||||||
selectedTab.selected = true;
|
selectedTab.selected = true;
|
||||||
|
|
||||||
|
console.log('HEY');
|
||||||
// The same selected was selected
|
// The same selected was selected
|
||||||
// we need to set root in the nested ion-nav if it exist
|
// we need to set root in the nested ion-nav if it exist
|
||||||
if (this.selectedTab === selectedTab) {
|
if (this.selectedTab === selectedTab) {
|
||||||
@ -157,19 +158,21 @@ export class Tabs {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
path: selectedTab.path,
|
path: selectedTab.getPath(),
|
||||||
focusNode: selectedTab
|
focusNode: selectedTab
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Method()
|
@Method()
|
||||||
getRoutes(): RouterEntries {
|
getRoutes(): RouterEntries {
|
||||||
return this.tabs.map(t => {
|
debugger;
|
||||||
|
const a = this.tabs.map(t => {
|
||||||
return {
|
return {
|
||||||
path: t.path,
|
path: t.getPath(),
|
||||||
id: t
|
id: t
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Method()
|
@Method()
|
||||||
|
@ -14,27 +14,21 @@
|
|||||||
<ion-app>
|
<ion-app>
|
||||||
<ion-tabs>
|
<ion-tabs>
|
||||||
<ion-tab title="Plain List" icon="star" path="">
|
<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>
|
||||||
|
|
||||||
<ion-tab title="Schedule" icon="globe" path="tab2">
|
<ion-tab title="Schedule" icon="globe" path="tab2">
|
||||||
<ion-nav root="page-two">
|
|
||||||
<ion-route path="" component="page-two"></ion-route>
|
<ion-route path="" component="page-two"></ion-route>
|
||||||
<ion-route path="path/to/page/three" component="page-three"></ion-route>
|
<ion-route path="path/to/page/three" component="page-three"></ion-route>
|
||||||
</ion-nav>
|
|
||||||
</ion-tab>
|
</ion-tab>
|
||||||
|
|
||||||
<ion-tab title="Stopwatch" icon="logo-facebook" path="tab3">
|
<ion-tab title="Stopwatch" icon="logo-facebook" path="tab3">
|
||||||
<ion-nav root="page-three">
|
|
||||||
<ion-route path="/" component="page-three"></ion-route>
|
<ion-route path="/" component="page-three"></ion-route>
|
||||||
</ion-nav>
|
|
||||||
</ion-tab>
|
</ion-tab>
|
||||||
|
|
||||||
<ion-tab title="Messages" icon="chatboxes" path="tab4">
|
<ion-tab title="Messages" icon="chatboxes" path="tab4">
|
||||||
<ion-nav root="page-tab">
|
|
||||||
<ion-route component="page-one"></ion-route>
|
<ion-route component="page-one"></ion-route>
|
||||||
<ion-route path="paginaaaa-two" component="page-two"></ion-route>
|
<ion-route path="paginaaaa-two" component="page-two"></ion-route>
|
||||||
</ion-nav>
|
|
||||||
</ion-tab>
|
</ion-tab>
|
||||||
</ion-tabs>
|
</ion-tabs>
|
||||||
|
|
||||||
|
@ -13,32 +13,26 @@
|
|||||||
|
|
||||||
<ion-app>
|
<ion-app>
|
||||||
<ion-tabs color="primary" translucent>
|
<ion-tabs color="primary" translucent>
|
||||||
<ion-tab title="Today" icon="calendar" path="">
|
<ion-tab title="Today" icon="calendar" path="" root="translucent-page-tab">
|
||||||
<translucent-page-tab class="ion-page"></translucent-page-tab>
|
<ion-route path="" component="translucent-page-tab"></ion-route>
|
||||||
</ion-tab>
|
</ion-tab>
|
||||||
|
|
||||||
<ion-tab title="Games" icon="planet" path="tab2">
|
<ion-tab title="Games" icon="planet" root="page-two">
|
||||||
<ion-nav root="page-two">
|
|
||||||
<ion-route path="" component="page-two"></ion-route>
|
<ion-route path="" component="page-two"></ion-route>
|
||||||
<ion-route path="path/to/page/three" component="page-three"></ion-route>
|
<ion-route path="path/to/page/three" component="page-three"></ion-route>
|
||||||
</ion-nav>
|
|
||||||
</ion-tab>
|
</ion-tab>
|
||||||
|
|
||||||
<ion-tab title="Apps" icon="logo-buffer" path="tab3">
|
<ion-tab title="Apps" icon="logo-buffer" root="page-three">
|
||||||
<ion-nav root="page-three">
|
|
||||||
<ion-route path="/" component="page-three"></ion-route>
|
<ion-route path="/" component="page-three"></ion-route>
|
||||||
</ion-nav>
|
|
||||||
</ion-tab>
|
</ion-tab>
|
||||||
|
|
||||||
<ion-tab title="Updates" icon="download" path="tab4" badge="7" badge-style="danger">
|
<ion-tab title="Updates" icon="download" badge="7" badge-style="danger" root="translucent-page-tab">
|
||||||
<ion-nav root="translucent-page-tab">
|
|
||||||
<ion-route component="page-one"></ion-route>
|
<ion-route component="page-one"></ion-route>
|
||||||
<ion-route path="paginaaaa-two" component="page-two"></ion-route>
|
<ion-route path="paginaaaa-two" component="page-two"></ion-route>
|
||||||
</ion-nav>
|
|
||||||
</ion-tab>
|
</ion-tab>
|
||||||
|
|
||||||
<ion-tab title="Search" icon="search" path="tab5">
|
<ion-tab title="Search" icon="search">
|
||||||
<translucent-page-tab class="ion-page"></translucent-page-tab>
|
<ion-route path="" component="translucent-page-tab"></ion-route>
|
||||||
</ion-tab>
|
</ion-tab>
|
||||||
</ion-tabs>
|
</ion-tabs>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user