Skip to content

Instantly share code, notes, and snippets.

@isidroamv
Forked from taivo/ion-tabs-swipable.js
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isidroamv/d784138ecfbc589e9e87 to your computer and use it in GitHub Desktop.
Save isidroamv/d784138ecfbc589e9e87 to your computer and use it in GitHub Desktop.
angular.module('yourModule')
.directive('tabsSwipable', ['$ionicGesture', function($ionicGesture){
//
// make ionTabs swipable. leftswipe -> nextTab, rightswipe -> prevTab
// Usage: just add this as an attribute in the ionTabs tag
// <ion-tabs tabs-swipable> ... </ion-tabs>
//
return {
restrict: 'A',
require: 'ionTabs',
link: function(scope, elm, attrs, tabsCtrl){
var onSwipeLeft = function(){
var target = tabsCtrl.selectedIndex() + 1;
if(target < tabsCtrl.tabs.length){
scope.$apply(tabsCtrl.select(target));
}
};
var onSwipeRight = function(){
var target = tabsCtrl.selectedIndex() - 1;
if(target >= 0){
scope.$apply(tabsCtrl.select(target));
}
};
var swipeGesture = $ionicGesture.on('swipeleft', onSwipeLeft, elm).on('swiperight', onSwipeRight);
scope.$on('$destroy', function() {
$ionicGesture.off(swipeGesture, 'swipeleft', onSwipeLeft);
$ionicGesture.off(swipeGesture, 'swiperight', onSwipeRight);
});
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment