mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
12
js/angular/directive/tabs.js
vendored
12
js/angular/directive/tabs.js
vendored
@@ -82,6 +82,18 @@ function($ionicTabsDelegate, $ionicConfig, $ionicHistory) {
|
||||
$scope.$hasTabsTop = isTabsTop && !isHidden;
|
||||
});
|
||||
|
||||
function emitLifecycleEvent(ev, data) {
|
||||
ev.stopPropagation();
|
||||
var selectedTab = tabsCtrl.selectedTab();
|
||||
if (selectedTab) {
|
||||
selectedTab.$emit(ev.name.replace('NavView', 'View'), data);
|
||||
}
|
||||
}
|
||||
|
||||
$scope.$on('$ionicNavView.beforeLeave', emitLifecycleEvent);
|
||||
$scope.$on('$ionicNavView.afterLeave', emitLifecycleEvent);
|
||||
$scope.$on('$ionicNavView.leave', emitLifecycleEvent);
|
||||
|
||||
$scope.$on('$destroy', function() {
|
||||
// variable to inform child tabs that they're all being blown away
|
||||
// used so that while destorying an individual tab, each one
|
||||
|
||||
6
js/angular/service/viewSwitcher.js
vendored
6
js/angular/service/viewSwitcher.js
vendored
@@ -315,6 +315,12 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe
|
||||
scope.$emit('$ionicView.leave', leavingData);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (scope && leavingData && leavingData.viewId) {
|
||||
scope.$emit('$ionicNavView.' + step + 'Leave', leavingData);
|
||||
if (step == 'after') {
|
||||
scope.$emit('$ionicNavView.leave', leavingData);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -920,6 +920,96 @@ describe('Ionic nav-view', function() {
|
||||
expect(leave.transitionId).toEqual(4);
|
||||
}));
|
||||
|
||||
it('should emit tab leaving events', inject(function ($state, $q, $timeout, $compile, $ionicConfig) {
|
||||
var beforeLeave, afterLeave, leave;
|
||||
scope.$on('$ionicView.beforeLeave', function(ev, d){
|
||||
beforeLeave = d;
|
||||
});
|
||||
scope.$on('$ionicView.afterLeave', function(ev, d){
|
||||
afterLeave = d;
|
||||
});
|
||||
scope.$on('$ionicView.leave', function(ev, d){
|
||||
leave = d;
|
||||
});
|
||||
|
||||
elem.append($compile('<ion-nav-view name="root"></ion-nav-view>')(scope));
|
||||
|
||||
$state.go(tab1page1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
|
||||
$state.go(tab1page2State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
|
||||
expect(beforeLeave.stateName).toEqual('tabAbstract.tab1page1');
|
||||
expect(afterLeave.stateName).toEqual('tabAbstract.tab1page1');
|
||||
expect(leave.stateName).toEqual('tabAbstract.tab1page1');
|
||||
|
||||
$state.go(tab2page1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
|
||||
expect(beforeLeave.stateName).toEqual('tabAbstract.tab1page2');
|
||||
expect(afterLeave.stateName).toEqual('tabAbstract.tab1page2');
|
||||
expect(leave.stateName).toEqual('tabAbstract.tab1page2');
|
||||
|
||||
$state.go(tab3page1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
|
||||
expect(beforeLeave.stateName).toEqual('tabAbstract.tab2page1');
|
||||
expect(afterLeave.stateName).toEqual('tabAbstract.tab2page1');
|
||||
expect(leave.stateName).toEqual('tabAbstract.tab2page1');
|
||||
|
||||
$state.go(tab1page1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
|
||||
expect(beforeLeave.stateName).toEqual('tabAbstract.tab3page1');
|
||||
expect(afterLeave.stateName).toEqual('tabAbstract.tab3page1');
|
||||
expect(leave.stateName).toEqual('tabAbstract.tab3page1');
|
||||
}));
|
||||
|
||||
it('should emit tab $ionicView.unloaded event', inject(function ($state, $q, $timeout, $compile, $ionicConfig) {
|
||||
$ionicConfig.views.maxCache(0);
|
||||
|
||||
var unloadedEvent;
|
||||
scope.$on('$ionicView.unloaded', function(ev, d){
|
||||
unloadedEvent = d;
|
||||
});
|
||||
|
||||
elem.append($compile('<ion-nav-view name="root"></ion-nav-view>')(scope));
|
||||
|
||||
$state.go(tab1page1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
|
||||
$state.go(tab1page2State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
|
||||
expect(unloadedEvent.stateName).toEqual('tabAbstract.tab1page1');
|
||||
|
||||
$state.go(tab2page1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
|
||||
expect(unloadedEvent.stateName).toEqual('tabAbstract.tab1page2');
|
||||
|
||||
$state.go(tab3page1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
|
||||
expect(unloadedEvent.stateName).toEqual('tabAbstract.tab2page1');
|
||||
|
||||
$state.go(tab1page1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
|
||||
expect(unloadedEvent.stateName).toEqual('tabAbstract.tab3page1');
|
||||
}));
|
||||
|
||||
it('should clear ion-nav-view cache', inject(function ($state, $q, $timeout, $compile, $ionicHistory) {
|
||||
elem.append($compile('<div><ion-nav-view></ion-nav-view></div>')(scope));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user