Skip to content

Commit

Permalink
fix(actionsheet): Fix slide-up animation, closes #713
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Mar 5, 2014
1 parent 5ebba71 commit 44b31e1
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 120 deletions.
2 changes: 1 addition & 1 deletion js/ext/angular/src/directive/ionicActionSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ angular.module('ionic.ui.actionSheet', [])
$element.bind('click', backdropClick);
},
template: '<div class="action-sheet-backdrop">' +
'<div class="action-sheet-wrapper action-sheet-up">' +
'<div class="action-sheet-wrapper">' +
'<div class="action-sheet">' +
'<div class="action-sheet-group">' +
'<div class="action-sheet-title" ng-if="titleText">{{titleText}}</div>' +
Expand Down
24 changes: 13 additions & 11 deletions js/ext/angular/src/service/ionicActionSheet.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ionic.service.platform', 'ionic.ui.actionSheet', 'ngAnimate'])

.factory('$ionicActionSheet', ['$rootScope', '$document', '$compile', '$animate', '$timeout',
'$ionicTemplateLoader', '$ionicPlatform',
function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoader, $ionicPlatform) {
.factory('$ionicActionSheet', ['$rootScope', '$document', '$compile', '$animate', '$timeout', '$ionicTemplateLoader', '$ionicPlatform',
function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoader, $ionicPlatform) {

return {
/**
* Load an action sheet with the given template string.
*
* A new isolated scope will be created for the
* A new isolated scope will be created for the
* action sheet and the new element will be appended into the body.
*
* @param {object} opts the options for this ActionSheet (see docs)
Expand All @@ -25,12 +24,13 @@ angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ioni
var sheetEl = angular.element(element[0].querySelector('.action-sheet-wrapper'));

var hideSheet = function(didCancel) {
$animate.leave(sheetEl, function() {
if(didCancel) {
sheetEl.removeClass('action-sheet-up');
if(didCancel) {
$timeout(function(){
opts.cancel();
}
});
}, 200);
}

$animate.removeClass(element, 'active', function() {
scope.$destroy();
});
Expand Down Expand Up @@ -77,8 +77,10 @@ angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ioni
scope.sheet = sheet;

$animate.addClass(element, 'active');
$animate.enter(sheetEl, element, null, function() {
});

$timeout(function(){
sheetEl.addClass('action-sheet-up');
}, 20);

return sheet;
}
Expand Down
12 changes: 11 additions & 1 deletion js/ext/angular/test/service/ionicActionSheet.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ describe('Ionic ActionSheet Service', function() {
expect(s.el.classList.contains('active')).toBe(true);
});

it('Should add .action-sheet-up to .action-sheet-wrapper', function() {
var s = sheet.show();
var el = angular.element(s.el);
var wrapper = angular.element(s.el.querySelector('.action-sheet-wrapper'));
expect(wrapper.length).toEqual(1);
expect(wrapper.hasClass('action-sheet-up')).toEqual(false);
timeout.flush();
expect(wrapper.hasClass('action-sheet-up')).toEqual(true);
});

it('Should handle hardware back button', function() {
// Fake cordova
window.device = {};
Expand All @@ -30,7 +40,7 @@ describe('Ionic ActionSheet Service', function() {
var s = sheet.show();

expect(angular.element(document.body).hasClass('action-sheet-open')).toBe(true);

ionic.trigger('backbutton', {
target: document
});
Expand Down
82 changes: 9 additions & 73 deletions scss/_action-sheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@
* --------------------------------------------------
*/

@-webkit-keyframes fadeInHalf {
from { background-color: rgba(0,0,0,0); }
to { background-color: rgba(0,0,0,0.5); }
}
@keyframes fadeInHalf {
from { background-color: rgba(0,0,0,0); }
to { background-color: rgba(0,0,0,0.5); }
}
@-webkit-keyframes fadeOutHalf {
from { background-color: rgba(0,0,0,0.5); }
to { background-color: rgba(0,0,0,0); }
}
@keyframes fadeOutHalf {
from { background-color: rgba(0,0,0,0.5); }
to { background-color: rgba(0,0,0,0); }
}

.action-sheet-backdrop {
position: fixed;
top: 0;
Expand All @@ -41,62 +24,21 @@
}
}

@-webkit-keyframes actionSheetUp {
0% {
@include translate3d(0, 100%, 0);
opacity: 0;
}
100% {
@include translate3d(0, 0, 0);
opacity: 1;
}
}
@-webkit-keyframes actionSheetOut {
0% {
@include translate3d(0, 0, 0);
opacity: 1;
}
100% {
@include translate3d(0, 100%, 0);
opacity: 0;
}
.action-sheet-wrapper {
@include translate3d(0, 100%, 0);
@include transition(all ease-in-out 300ms);
position: absolute;
bottom: 0;
width: 100%;
}
$slide-in-up-function: cubic-bezier(.1, .7, .1, 1);

.action-sheet-up {
// Start it down low
@include translate3d(0, 0%, 0);
opacity: 1;

&.ng-enter, .ng-enter {
// Start it down low
@include translate3d(0, 100%, 0);

@include animation-duration(400ms);
@include animation-fill-mode(both);
@include animation-timing-function($slide-in-up-function);
// Start hidden
opacity: 0;
}

&.ng-enter-active, .ng-enter-active {
@include animation-name(actionSheetUp);
}

&.ng-leave, .ng-leave {
@include animation-duration(400ms);
@include animation-fill-mode(both);
@include animation-timing-function($slide-in-up-function);
}

&.ng-leave-active, .ng-leave {
@include animation-name(actionSheetOut);
}
@include translate3d(0, 0, 0);
}

.action-sheet {
margin-left: 15px;
margin-right: 15px;
margin-left: 15px;
margin-right: 15px;
width: auto;
z-index: $z-index-action-sheet;
overflow: hidden;
Expand All @@ -118,12 +60,6 @@ $slide-in-up-function: cubic-bezier(.1, .7, .1, 1);
}
}

.action-sheet-wrapper {
width: 100%;
position: fixed;
bottom: 0;
}

.action-sheet-title {
padding: 10px;
color: lighten($base-color, 40%);
Expand Down
96 changes: 62 additions & 34 deletions scss/_animations.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,50 @@
* and pretty easy on performance. They can be overidden
* and enhanced easily.
*/
$transition-duration: 250ms;

$transition-duration: 250ms;
$slide-in-up-function: cubic-bezier(.1, .7, .1, 1);


/**
* Keyframes
* --------------------------------------------------
*/

$slide-in-up-function: cubic-bezier(.1, .7, .1, 1);
// Slide In From The Bottom To The Top
// -------------------------------

@-webkit-keyframes slideInUp {
0% {
@include translate3d(0, 100%, 0);
opacity: 1;
}
100% {
@include translate3d(0, 0, 0);
opacity: 1;
}
0% { -webkit-transform: translate3d(0, 100%, 0); }
100% { -webkit-transform: translate3d(0, 0, 0); }
}
@-moz-keyframes slideInUp {
0% {
@include translate3d(0, 100%, 0);
opacity: 1;
}
100% {
@include translate3d(0, 0, 0);
opacity: 1;
}
0% { -moz-transform: translate3d(0, 100%, 0); }
100% { -moz-transform: translate3d(0, 0, 0); }
}
@keyframes slideInUp {
0% { transform: translate3d(0, 100%, 0); }
100% { transform: translate3d(0, 0, 0); }
}


// Slide Out From The Top To Bottom
// -------------------------------

@-webkit-keyframes slideOutUp {
0% {
@include translate3d(0, 0, 0);
opacity: 1;
}
100% {
@include translate3d(0, 100%, 0);
opacity: 1;
}
0% { -webkit-transform: translate3d(0, 0, 0); }
100% { -webkit-transform: translate3d(0, 100%, 0); }
}
@-moz-keyframes slideOutUp {
0% {
@include translate3d(0, 0, 0);
opacity: 1;
}
100% {
@include translate3d(0, 100%, 0);
opacity: 1;
}
0% { -moz-transform: translate3d(0, 0, 0); }
100% { -moz-transform: translate3d(0, 100%, 0); }
}
@keyframes slideOutUp {
0% { transform: translate3d(0, 0, 0); }
100% { transform: translate3d(0, 100%, 0); }
}


// Slide In From Left
// -------------------------------

Expand Down Expand Up @@ -157,6 +151,40 @@ $slide-in-up-function: cubic-bezier(.1, .7, .1, 1);
}


// Fade Half In
// -------------------------------

@-webkit-keyframes fadeInHalf {
from { background-color: rgba(0,0,0,0); }
to { background-color: rgba(0,0,0,0.5); }
}
@-moz-keyframes fadeInHalf {
from { background-color: rgba(0,0,0,0); }
to { background-color: rgba(0,0,0,0.5); }
}
@keyframes fadeInHalf {
from { background-color: rgba(0,0,0,0); }
to { background-color: rgba(0,0,0,0.5); }
}


// Fade Half Out
// -------------------------------

@-webkit-keyframes fadeOutHalf {
from { background-color: rgba(0,0,0,0.5); }
to { background-color: rgba(0,0,0,0); }
}
@-moz-keyframes fadeOutHalf {
from { background-color: rgba(0,0,0,0.5); }
to { background-color: rgba(0,0,0,0); }
}
@keyframes fadeOutHalf {
from { background-color: rgba(0,0,0,0.5); }
to { background-color: rgba(0,0,0,0); }
}


// Spin
// -------------------------------

Expand Down

0 comments on commit 44b31e1

Please sign in to comment.