Last active
March 21, 2016 18:09
-
-
Save alexmgrant/2487e49b46bdfc864d17 to your computer and use it in GitHub Desktop.
An added animation for ionic 1.0 that slides the view from the bottom to the top.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* I have a gloabal ctrl which sits within my tabs.html. This way I have access to the global view model (controller) whereveer I want. */ | |
TabsCtrl.$inject = ['$ionicViewSwitcher', '$ionicHistory']; | |
export default function TabsCtrl($ionicViewSwitcher, $ionicHistory) { | |
/* use our custom animation on click when this method is called */ | |
function actionView(isExit) { | |
if ($ionicHistory.backView() !== null) { | |
var backView = $ionicHistory.backView(); | |
/* sometimes we want native transitions even though we are returning from a slide in up animation. | |
We can set those views here and the function will exit thus calling native transition animations */ | |
if ((backView.stateName === 'tab.someview.child' || backView.stateName === 'tab.someview.child' || backView.stateName === 'tab.someview.child') && !isExit) { | |
return; | |
} | |
} | |
/* call custom animation */ | |
$ionicViewSwitcher.nextTransition('actionView'); | |
/* you can pass a boolean value to our toggleSlide() which will bring you back to ionics history stask root view */ | |
if (isExit) { | |
$ionicHistory.nextViewOptions({ | |
historyRoot: true | |
}); | |
} | |
} | |
/* check to see if we should hide ionic's header bar */ | |
$scope.$on('$ionicView.beforeEnter', function () { | |
currentState = $state.current.name; | |
var stateData = $state.current.data; | |
var userHistoryUrl = $ionicHistory.backView(); | |
if (stateData.slideInUp === true) { | |
hideHeaderBar(); | |
} else if (stateData.slideInUp === false || typeof stateData.slideInUp === 'undefined') { | |
$ionicNavBarDelegate.showBar(true); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- include this in all your views via ng-include. Not ideal, | |
but if you want the header to slide in with your view you'll need to hide | |
ionic's default header and insert your own --> | |
<ion-header-bar> | |
<a class="ion-ios-arrow-back" | |
ng-click="global.toggleSlide(); global.userHistoryBack();" | |
nav-direction="back"></a> | |
<h1>{{global.headerTitle}}</h1> | |
</ion-header-bar> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* this is where we define our new transition. We basically add our custom animation to $ionicConfigProvider | |
Then we call it when we would like to use it on click. | |
This is typescript, but you can convert to JS/Angular 1.x with the normal angular.module('MyApp').config('slideInUp'); syntax */ | |
config.$inject = ['$ionicConfigProvider']; | |
export default function config($ionicConfigProvider) { | |
$ionicConfigProvider.transitions.views.actionView = function (enteringEle, leavingEle, direction, shouldAnimate) { | |
function setStyles(ele, opacity, y, boxShadowOpacity) { | |
var css:any = {}; | |
css[ionic.CSS.TRANSITION_DURATION] = d.shouldAnimate ? '' : 0; | |
css.opacity = opacity; | |
if (boxShadowOpacity > -1) { | |
css.boxShadow = '0 0 10px rgba(0,0,0,' + (d.shouldAnimate ? boxShadowOpacity * 0.45 : 0.3) + ')'; | |
} | |
css[ionic.CSS.TRANSFORM] = 'translate3d(0,' + y + '%,0)'; | |
ionic.DomUtil.cachedStyles(ele, css); | |
} | |
var d = { | |
run: function (step) { | |
if (direction === 'forward') { | |
setStyles(enteringEle, 1, (1 - step) * 99, 1 - step); // starting at 98% prevents a flicker | |
} else if (direction === 'back') { | |
setStyles(leavingEle, 1, step * 100, 1 - step); | |
} else { | |
// swap, enter, exit | |
setStyles(enteringEle, 1, 0, -1); | |
setStyles(leavingEle, 0, 0, -1); | |
} | |
}, | |
shouldAnimate: shouldAnimate && (direction === 'forward' || direction === 'back') | |
}; | |
return d; | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="#/tab/another-view" ng-click="global.toggleSlide()">click</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment