mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
154 lines
6.3 KiB
TypeScript
154 lines
6.3 KiB
TypeScript
import {ChangeDetectorRef, Component, Directive, ElementRef, Host, Optional, forwardRef, Inject, NgZone, Compiler, AppViewManager, Renderer, ViewContainerRef} from 'angular2/core';
|
|
|
|
import {IonicApp} from '../app/app';
|
|
import {Config} from '../../config/config';
|
|
import {Keyboard} from '../../util/keyboard';
|
|
import {ConfigComponent} from '../../config/decorators';
|
|
import {NavController} from './nav-controller';
|
|
import {ViewController} from './view-controller';
|
|
|
|
/**
|
|
* _For a quick walkthrough of navigation in Ionic, check out the
|
|
* [Navigation section](../../../../components/#navigation) of the Component
|
|
* docs._
|
|
*
|
|
* Nav is a basic navigation controller component. As a subclass of NavController
|
|
* you use it to navigate to pages in your app and manipulate the navigation stack.
|
|
* Nav automatically animates transitions between pages for you.
|
|
*
|
|
* For more information on using navigation controllers like Nav or [Tab](../../Tabs/Tab/),
|
|
* take a look at the [NavController API reference](../NavController/).
|
|
*
|
|
* You must set a root page (where page is any [@Page](../../config/Page/)
|
|
* component) to be loaded initially by any Nav you create, using
|
|
* the 'root' property:
|
|
*
|
|
* ```ts
|
|
* import {GettingStartedPage} from 'getting-started';
|
|
* @App({
|
|
* template: `<ion-nav [root]="rootPage"></ion-nav>`
|
|
* })
|
|
* class MyApp {
|
|
* constructor(){
|
|
* this.rootPage = GettingStartedPage;
|
|
* }
|
|
* }
|
|
* ```
|
|
*
|
|
* <h2 id="back_navigation">Back navigation</h2>
|
|
* If a [page](../NavController/#creating_pages) you navigate to has a [NavBar](../NavBar/),
|
|
* Nav will automatically add a back button to it if there is a page
|
|
* before the one you are navigating to in the navigation stack.
|
|
*
|
|
* Additionally, specifying the `swipe-back-enabled` property will allow you to
|
|
* swipe to go back:
|
|
* ```html
|
|
* <ion-nav swipe-back-enabled="false" [root]="rootPage"></ion-nav>
|
|
* ```
|
|
*
|
|
* Here is a diagram of how Nav animates smoothly between pages:
|
|
*
|
|
* <div class="highlight less-margin">
|
|
* <pre>
|
|
* +-------+
|
|
* | App |
|
|
* +---+---+
|
|
* <ion-app>
|
|
* |
|
|
* +------------+-------------+
|
|
* | Ionic Nav Controller |
|
|
* +------------+-------------+
|
|
* <ion-nav>
|
|
* |
|
|
* |
|
|
* Page 3 +--------------------+ LoginPage
|
|
* Page 2 +--------------------+ |
|
|
* Page 1 +--------------------+ | | +--------------------+
|
|
* | | Header |<-----------------| Login |
|
|
* +--------------------+ | | +--------------------+
|
|
* | | | | | | | Username: |
|
|
* | | | | | | | Password: |
|
|
* | | | Page 3 is | | | | |
|
|
* | | | only content | | | | |
|
|
* | | | |<-----------------| |
|
|
* | | | | | | | |
|
|
* | | | | | | | |
|
|
* | +------------------|-+ | | |
|
|
* | | Footer |-|-+ | |
|
|
* | +------------------|-+ | |
|
|
* +--------------------+ +--------------------+
|
|
*
|
|
* +--------------------+ +--------------------+ +--------------------+
|
|
* | Header | | Content | | Content |
|
|
* +--------------------+ | | | |
|
|
* | Content | | | | |
|
|
* | | | | | |
|
|
* | | | | | |
|
|
* | | | | | |
|
|
* | | | | | |
|
|
* | | | | | |
|
|
* | | | | | |
|
|
* | | | | | |
|
|
* | | +--------------------+ | |
|
|
* | | | Footer | | |
|
|
* +--------------------+ +--------------------+ +--------------------+
|
|
*
|
|
* </pre>
|
|
* </div>
|
|
*
|
|
* @see {@link /docs/v2/components#navigation Navigation Component Docs}
|
|
*/
|
|
@ConfigComponent({
|
|
selector: 'ion-nav',
|
|
inputs: [
|
|
'root'
|
|
],
|
|
defaultInputs: {
|
|
'swipeBackEnabled': true
|
|
},
|
|
template: '<template #contents></template>'
|
|
})
|
|
export class Nav extends NavController {
|
|
|
|
constructor(
|
|
@Optional() hostNavCtrl: NavController,
|
|
@Optional() viewCtrl: ViewController,
|
|
app: IonicApp,
|
|
config: Config,
|
|
keyboard: Keyboard,
|
|
elementRef: ElementRef,
|
|
compiler: Compiler,
|
|
viewManager: AppViewManager,
|
|
zone: NgZone,
|
|
renderer: Renderer,
|
|
cd: ChangeDetectorRef
|
|
) {
|
|
super(hostNavCtrl, app, config, keyboard, elementRef, 'contents', compiler, viewManager, zone, renderer, cd);
|
|
|
|
if (viewCtrl) {
|
|
// an ion-nav can also act as an ion-page within a parent ion-nav
|
|
// this would happen when an ion-nav nests a child ion-nav.
|
|
viewCtrl.setContent(this);
|
|
viewCtrl.setContentRef(elementRef);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
*/
|
|
ngOnInit() {
|
|
super.ngOnInit();
|
|
|
|
if (this.root) {
|
|
if (typeof this.root !== 'function') {
|
|
throw 'The [root] property in <ion-nav> must be given a reference to a component class from within the constructor.';
|
|
}
|
|
this.push(this.root);
|
|
}
|
|
|
|
// default the swipe back to be enabled
|
|
this.isSwipeBackEnabled( (this.swipeBackEnabled || '').toString() !== 'false' );
|
|
}
|
|
|
|
}
|