From 942168465126dc30f6db3bcf3982bd13e1d7ab27 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Mon, 15 Jun 2015 08:03:27 -0500 Subject: [PATCH] tabs back btn updates --- ionic/components/tabs/tabs.js | 32 ++++++++++++++++++------ ionic/components/view/view-controller.js | 8 +++--- ionic/components/view/view-item.js | 14 ++++++----- ionic/transitions/transition.js | 2 +- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/ionic/components/tabs/tabs.js b/ionic/components/tabs/tabs.js index 4be21ae67f..21994b8ca6 100644 --- a/ionic/components/tabs/tabs.js +++ b/ionic/components/tabs/tabs.js @@ -55,15 +55,31 @@ export class Tabs extends ViewController { injector: Injector ) { super(parentViewCtrl, compiler, elementRef, loader, injector); - this.item = viewItem; - this.item.navbarView = () => { - let activeTab = this.getActive(); - if (activeTab && activeTab.instance) { - return activeTab.instance.navbarView(); - } - return {}; - }; + // Tabs may also be an actual ViewItem which was navigated to + // if Tabs is static and not navigated to within a ViewController + // then skip this and don't treat it as it's own ViewItem + if (viewItem) { + this.item = viewItem; + + // special overrides for the Tabs ViewItem + // the Tabs ViewItem does not have it's own navbar + // so find the navbar it should use within it's active Tab + viewItem.navbarView = () => { + let activeTab = this.getActive(); + if (activeTab && activeTab.instance) { + return activeTab.instance.navbarView(); + } + return {}; + }; + + // a Tabs ViewItem should not have a back button + // enableBack back button should be determined by the + // the active ViewItem with a navbar + viewItem.enableBack = () => { + return false; + }; + } this.childNavbar(true); diff --git a/ionic/components/view/view-controller.js b/ionic/components/view/view-controller.js index 5e07b9e35b..18a293f70d 100644 --- a/ionic/components/view/view-controller.js +++ b/ionic/components/view/view-controller.js @@ -276,11 +276,9 @@ export class ViewController { } swipeBackEnabled() { - if (this.items.length > 1) { - let activeItem = this.getActive(); - if (activeItem) { - return activeItem.enableBack; - } + let activeItem = this.getActive(); + if (activeItem) { + return activeItem.enableBack(); } return false; } diff --git a/ionic/components/view/view-item.js b/ionic/components/view/view-item.js index 42d8c1f3ce..3178080741 100644 --- a/ionic/components/view/view-item.js +++ b/ionic/components/view/view-item.js @@ -17,9 +17,6 @@ export class ViewItem { this.state = 0; this.disposals = []; - // if it's possible to go back from this nav item - this.enableBack = false; - this.protos = {}; this._nbItms = []; this._promises = []; @@ -32,9 +29,6 @@ export class ViewItem { stage(callback) { let viewCtrl = this.viewCtrl; - // update if it's possible to go back from this nav item - this.enableBack = viewCtrl && !!viewCtrl.getPrevious(this); - if (this.instance || !viewCtrl) { // already compiled this view return callback(); @@ -152,6 +146,14 @@ export class ViewItem { }; } + enableBack() { + // update if it's possible to go back from this nav item + if (this.viewCtrl) { + return !!this.viewCtrl.getPrevious(this); + } + return false; + } + setInstance(instance) { this.instance = instance; } diff --git a/ionic/transitions/transition.js b/ionic/transitions/transition.js index 1c71c5b15a..51a99422a8 100644 --- a/ionic/transitions/transition.js +++ b/ionic/transitions/transition.js @@ -26,7 +26,7 @@ export class Transition extends Animation { let enteringNavbar = this.enteringNavbar = new Animation(enteringItem.navbarElement()); enteringNavbar.before.addClass(SHOW_NAVBAR_CSS); - if (enteringItem.enableBack) { + if (enteringItem.enableBack()) { // only animate in the back button if the entering view has it enabled let enteringBackButton = this.enteringBackButton = new Animation(enteringItem.backButtonElement()); enteringBackButton