Skip to content

Commit

Permalink
chore(nav): create nav-interfaces file
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Jul 12, 2016
1 parent 8c2f0b4 commit cca3309
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 81 deletions.
2 changes: 1 addition & 1 deletion src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export { Modal, ModalController } from './components/modal/modal';
export { ModalOptions } from './components/modal/modal-options';
export { Nav } from './components/nav/nav';
export { NavController } from './components/nav/nav-controller';
export { NavOptions } from './components/nav/nav-options';
export { NavOptions } from './components/nav/nav-interfaces';
export { NavParams } from './components/nav/nav-params';
export { NavPop } from './components/nav/nav-pop';
export { NavPush } from './components/nav/nav-push';
Expand Down
2 changes: 1 addition & 1 deletion src/components/action-sheet/action-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ActionSheetCmp } from './action-sheet-component';
import { ActionSheetOptions } from './action-sheet-options';
import { App } from '../app/app';
import { isPresent } from '../../util/util';
import { NavOptions } from '../nav/nav-options';
import { NavOptions } from '../nav/nav-interfaces';
import { ViewController } from '../nav/view-controller';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/components/alert/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { App } from '../app/app';
import { AlertCmp } from './alert-component';
import { AlertOptions, AlertInputOptions } from './alert-options';
import { isPresent } from '../../util/util';
import { NavOptions } from '../nav/nav-options';
import { NavOptions } from '../nav/nav-interfaces';
import { ViewController } from '../nav/view-controller';


Expand Down
2 changes: 1 addition & 1 deletion src/components/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Title } from '@angular/platform-browser';
import { ClickBlock } from '../../util/click-block';
import { Config } from '../../config/config';
import { NavController } from '../nav/nav-controller';
import { NavOptions } from '../nav/nav-options';
import { NavOptions } from '../nav/nav-interfaces';
import { NavPortal } from '../nav/nav-portal';
import { Platform } from '../../platform/platform';

Expand Down
2 changes: 1 addition & 1 deletion src/components/loading/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Config } from '../../config/config';
import { isPresent } from '../../util/util';
import { LoadingCmp } from './loading-component';
import { LoadingOptions } from './loading-options';
import { NavOptions } from '../nav/nav-options';
import { NavOptions } from '../nav/nav-interfaces';
import { ViewController} from '../nav/view-controller';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/components/modal/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { App } from '../app/app';
import { isPresent } from '../../util/util';
import { ModalCmp } from './modal-component';
import { ModalOptions } from './modal-options';
import { NavOptions } from '../nav/nav-options';
import { NavOptions } from '../nav/nav-interfaces';
import { ViewController } from '../nav/view-controller';


Expand Down
68 changes: 25 additions & 43 deletions src/components/nav/nav-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Ion } from '../ion';
import { isBlank, pascalCaseToDashCase } from '../../util/util';
import { Keyboard } from '../../util/keyboard';
import { MenuController } from '../menu/menu-controller';
import { NavOptions } from './nav-interfaces';
import { NavParams } from './nav-params';
import { NavOptions } from './nav-options';
import { SwipeBackGesture } from './swipe-back';
import { Transition } from '../../transitions/transition';
import { ViewController } from './view-controller';
Expand Down Expand Up @@ -218,11 +218,6 @@ export class NavController extends Ion {
*/
id: string;

/**
* @private
*/
routers: any[] = [];

/**
* @private
*/
Expand All @@ -241,7 +236,7 @@ export class NavController extends Ion {
/**
* @private
*/
_trnsTime: number = 0;
trnsTime: number = 0;

constructor(
parent: any,
Expand Down Expand Up @@ -325,7 +320,7 @@ export class NavController extends Ion {
}

// set the nav direction to "back" if it wasn't set
opts.direction = opts.direction || 'back';
opts.direction = opts.direction || DIRECTION_BACK;

let resolve: any;
let promise = new Promise(res => { resolve = res; });
Expand Down Expand Up @@ -493,7 +488,7 @@ export class NavController extends Ion {
view.state = STATE_INACTIVE;

// give this inserted view an ID
this._incId(view);
view.id = this.id + '-' + (++this._ids);

// insert the entering view into the correct index in the stack
this._views.splice(insertIndex + i, 0, view);
Expand Down Expand Up @@ -584,7 +579,7 @@ export class NavController extends Ion {
}

// default the direction to "back"
opts.direction = opts.direction || 'back';
opts.direction = opts.direction || DIRECTION_BACK;

// figure out the states of each view in the stack
let leavingView = this._remove(startIndex, removeCount);
Expand Down Expand Up @@ -989,6 +984,7 @@ export class NavController extends Ion {
// so just update the local transitioning information
let duration = parentTransitionEndTime - Date.now();
this.setTransitioning(true, duration);

} else {
// this is the only active transition (for now), so disable the app
let keyboardDurationPadding = 0;
Expand Down Expand Up @@ -1151,16 +1147,9 @@ export class NavController extends Ion {
this._app && this._app.setEnabled(true);
}

// update that this nav is not longer actively transitioning
this.setTransitioning(false);

if (direction !== null && hasCompleted && !this.isPortal) {
// notify router of the state change if a direction was provided
// multiple routers can exist and each should be notified
this.routers.forEach(router => {
router.stateChange(direction, enteringView);
});
}

// see if we should add the swipe back gesture listeners or not
this._sbCheck();

Expand Down Expand Up @@ -1332,7 +1321,7 @@ export class NavController extends Ion {
swipeBackStart() {
// default the direction to "back"
let opts: NavOptions = {
direction: 'back',
direction: DIRECTION_BACK,
progressAnimation: true
};

Expand Down Expand Up @@ -1440,15 +1429,19 @@ export class NavController extends Ion {
* Returns if the nav controller is actively transitioning or not.
* @return {boolean}
*/
isTransitioning(): boolean {
return (this._trnsTime > Date.now());
isTransitioning(includeAncestors?: boolean): boolean {
let now = Date.now();
if (includeAncestors && this._getLongestTrans(now) > 0) {
return true;
}
return (this.trnsTime > now);
}

/**
* @private
*/
setTransitioning(isTransitioning: boolean, fallback: number = 700) {
this._trnsTime = (isTransitioning ? Date.now() + fallback : 0);
this.trnsTime = (isTransitioning ? Date.now() + fallback : 0);
}

/**
Expand All @@ -1459,13 +1452,13 @@ export class NavController extends Ion {
* thus giving us the longest transition duration
*/
private _getLongestTrans(now: number) {
let parentNav: NavController = <NavController> this.parent;
let transitionEndTime: number = -1;
let parentNav = <NavController>this.parent;
let transitionEndTime = -1;
while (parentNav) {
if (parentNav._trnsTime > transitionEndTime) {
transitionEndTime = parentNav._trnsTime;
if (parentNav.trnsTime > transitionEndTime) {
transitionEndTime = parentNav.trnsTime;
}
parentNav = <NavController> parentNav.parent;
parentNav = parentNav.parent;
}
// only check if the transitionTime is greater than the current time once
return transitionEndTime > 0 && transitionEndTime > now ? transitionEndTime : 0;
Expand Down Expand Up @@ -1591,20 +1584,6 @@ export class NavController extends Ion {
});
}

/**
* @private
*/
registerRouter(router: any) {
this.routers.push(router);
}

/**
* @private
*/
private _incId(view: ViewController) {
view.id = this.id + '-' + (++this._ids);
}

/**
* @private
*/
Expand All @@ -1626,7 +1605,7 @@ export class NavController extends Ion {
enteringView.setZIndex(this.isPortal ? PORTAL_ZINDEX : INIT_ZINDEX, this._renderer);
}

} else if (direction === 'back') {
} else if (direction === DIRECTION_BACK) {
// moving back
enteringView.setZIndex(leavingView.zIndex - 1, this._renderer);

Expand All @@ -1650,7 +1629,10 @@ const STATE_REMOVE_AFTER_TRANS = 8;
const STATE_CANCEL_ENTER = 9;
const STATE_FORCE_ACTIVE = 10;

export const DIRECTION_BACK = 'back';
export const DIRECTION_FORWARD = 'forward';

const INIT_ZINDEX = 100;
const PORTAL_ZINDEX = 9999;

let ctrlIds = -1;
let ctrlIds = -1;
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface NavOptions {
direction?: string;
duration?: number;
easing?: string;
id?: string;
keyboardClose?: boolean;
preload?: boolean;
transitionDelay?: number;
Expand Down
8 changes: 5 additions & 3 deletions src/components/nav/nav-pop.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Directive, Optional } from '@angular/core';

import { NavController } from './nav-controller';


/**
* @name NavPop
* @description
Expand All @@ -10,10 +10,11 @@ import { NavController } from './nav-controller';
* @usage
* ```html
* <ion-content>
* <div block button nav-pop>go back</div>
*
* <button navPop>Go Back</button>
*
* </ion-content>
* ```
* This will go back one page in the navigation stack
*
* Similar to {@link /docs/v2/api/components/nav/NavPush/ `NavPush` }
* @demo /docs/v2/demos/navigation/
Expand All @@ -34,6 +35,7 @@ export class NavPop {
console.error('nav-pop must be within a NavController');
}
}

/**
* @private
*/
Expand Down
30 changes: 15 additions & 15 deletions src/components/nav/test/nav-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ export function run() {
it('should return 0 when transition end time is less than now', () => {
// arrange
nav.parent = {
_trnsTime: Date.now() - 5
trnsTime: Date.now() - 5
};
// act
let returnedValue = nav._getLongestTrans(Date.now());
Expand All @@ -1567,7 +1567,7 @@ export function run() {
it('should return 0 when parent transition time not set', () => {
// arrange
nav.parent = {
_trnsTime: undefined
trnsTime: undefined
};
// act
let returnedValue = nav._getLongestTrans(Date.now());
Expand All @@ -1579,7 +1579,7 @@ export function run() {
// arrange
let expectedReturnValue = Date.now() + 100;
nav.parent = {
_trnsTime: expectedReturnValue
trnsTime: expectedReturnValue
};
// act
let returnedValue = nav._getLongestTrans(Date.now());
Expand All @@ -1591,16 +1591,16 @@ export function run() {
// arrange
let expectedReturnValue = Date.now() + 100;
let firstParent = {
_trnsTime: expectedReturnValue
trnsTime: expectedReturnValue
};
let secondParent = {
_trnsTime: Date.now() + 50
trnsTime: Date.now() + 50
};
let thirdParent = {
_trnsTime: Date.now()
trnsTime: Date.now()
};
let fourthParent = {
_trnsTime: Date.now() + 20
trnsTime: Date.now() + 20
};
firstParent.parent = secondParent;
secondParent.parent = thirdParent;
Expand All @@ -1616,16 +1616,16 @@ export function run() {
// arrange
let expectedReturnValue = Date.now() + 100;
let firstParent = {
_trnsTime: Date.now()
trnsTime: Date.now()
};
let secondParent = {
_trnsTime: Date.now() + 50
trnsTime: Date.now() + 50
};
let thirdParent = {
_trnsTime: expectedReturnValue
trnsTime: expectedReturnValue
};
let fourthParent = {
_trnsTime: Date.now() + 20
trnsTime: Date.now() + 20
};
firstParent.parent = secondParent;
secondParent.parent = thirdParent;
Expand All @@ -1641,16 +1641,16 @@ export function run() {
// arrange
let expectedReturnValue = Date.now() + 100;
let firstParent = {
_trnsTime: Date.now()
trnsTime: Date.now()
};
let secondParent = {
_trnsTime: Date.now() + 50
trnsTime: Date.now() + 50
};
let thirdParent = {
_trnsTime: Date.now() + 20
trnsTime: Date.now() + 20
};
let fourthParent = {
_trnsTime: expectedReturnValue
trnsTime: expectedReturnValue
};
firstParent.parent = secondParent;
secondParent.parent = thirdParent;
Expand Down
2 changes: 1 addition & 1 deletion src/components/nav/view-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Footer, Header } from '../toolbar/toolbar';
import { isPresent, merge } from '../../util/util';
import { Navbar } from '../navbar/navbar';
import { NavController } from './nav-controller';
import { NavOptions } from './nav-options';
import { NavOptions } from './nav-interfaces';
import { NavParams } from './nav-params';


Expand Down
2 changes: 1 addition & 1 deletion src/components/picker/picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EventEmitter, Injectable, Output } from '@angular/core';

import { App } from '../app/app';
import { isPresent } from '../../util/util';
import { NavOptions } from '../nav/nav-options';
import { NavOptions } from '../nav/nav-interfaces';
import { PickerCmp } from './picker-component';
import { PickerOptions, PickerColumn } from './picker-options';
import { ViewController } from '../nav/view-controller';
Expand Down
2 changes: 1 addition & 1 deletion src/components/popover/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';

import { App } from '../app/app';
import { isPresent } from '../../util/util';
import { NavOptions } from '../nav/nav-options';
import { NavOptions } from '../nav/nav-interfaces';
import { PopoverCmp } from './popover-component';
import { PopoverOptions } from './popover-options';
import { ViewController } from '../nav/view-controller';
Expand Down
2 changes: 1 addition & 1 deletion src/components/tabs/tab-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Tab } from './tab';
selector: '.tab-button',
host: {
'[attr.id]': 'tab._btnId',
'[attr.aria-controls]': 'tab._panelId',
'[attr.aria-controls]': 'tab._tabId',
'[attr.aria-selected]': 'tab.isSelected',
'[class.has-title]': 'hasTitle',
'[class.has-icon]': 'hasIcon',
Expand Down
Loading

0 comments on commit cca3309

Please sign in to comment.