From aff112a5a1e49a051a3935790f26c1fc004c41ad Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Thu, 5 Nov 2015 21:11:16 -0600 Subject: [PATCH] feat(tabs): more touchActive features --- ionic/components/tabs/tabs.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/ionic/components/tabs/tabs.ts b/ionic/components/tabs/tabs.ts index 4dcfd643b3..05b86c0f3f 100644 --- a/ionic/components/tabs/tabs.ts +++ b/ionic/components/tabs/tabs.ts @@ -217,15 +217,36 @@ export class Tabs extends Ion { /** * @private - * "Touch" the active tab, either going back to the root view of the tab - * or scrolling the tab to the top + * "Touch" the active tab, going back to the root view of the tab + * or optionally letting the tab handle the event */ touchActive(tab) { + let active = tab.getActive(); + + if(!active) { + return Promise.resolve(); + } + + let instance = active.instance; + + // If they have a custom tab selected handler, call it + if(instance.tabSelected) { + return instance.tabSelected(); + } + + // If we're a few pages deep, pop to root if (tab.length() > 1) { // Pop to the root view return tab.popToRoot(); } + // Otherwise, if the page we're on is not our real root, reset it to our + // default root type + if(tab.root != active.componentType) { + return tab.setRoot(tab.root); + } + + // And failing all of that, we do something safe and secure return Promise.resolve(); }