Ionic v1 modal destroyed before leave animation is complete - angularjs

When using the default slide-in-up animation for an Ionic (v1) modal, the modal leave animation looks perfect. But when substituting a different animation ( I am using slide-in-right) the modal is destroyed (i.e. removed from the DOM) before the leave animation is done. Here's my code:
JS:
//create the modal
$ionicModal.fromTemplateUrl('templates/my-modal.html', function(modal) {
$scope.myModal = modal;
}, {
scope: $scope,
animation: 'slide-in-right'
});
//show the modal
$scope.myModal.show()
//hide the modal
$scope.myModal.hide();
and the CSS (the timings are long just for debugging purposes):
.slide-in-right {
-webkit-transform: translateX(100%);
transform: translateX(100%); }
.slide-in-right.ng-enter, .slide-in-right > .ng-enter {
-webkit-transition: all cubic-bezier(0.1, 0.7, 0.1, 1) 2000ms;
transition: all cubic-bezier(0.1, 0.7, 0.1, 1) 2000ms; }
.slide-in-right.ng-enter-active, .slide-in-right > .ng-enter-active {
-webkit-transform: translateX(0);
transform: translateX(0); }
.slide-in-right.ng-leave, .slide-in-right > .ng-leave {
-webkit-transition: all linear 2800ms;
transition: all linear 2800ms; }
This causes a noticeable UX hiccup, since the modal is only half way through the leave animation before it just disappears. You can see this here:
http://codepen.io/frey1esm/pen/QvOQjO
The leave timing in this codepen is 2500ms so that's how long the modal should be visible as it slides out to the left. But it gets removed almost instantly. IS there a way to delay the removal of the modal from the DOM?

i dont know if there a good ionic answer to that
anyway my workaround will be custom class conditions
http://codepen.io/islam4hak/pen/JNOepN
on the ion modal use a condition class name
<ion-modal-view ng-class="GoingAway==1 ? 'slide-in-left ng-leave' : ' '">
and for the controller
$scope.GoingAway = 0;
$scope.CustomHide = function(e){
$scope.GoingAway = 1;
setTimeout(function(){
$scope.modal.hide();
$scope.GoingAway = 0;
},2600)
}
Hope that this work for you

Related

loading a simple angularjs jsfiddle

AngularJS won't show my transition in this jsfiddle
I've tried everything I can think of regarding setting this up
Here's the jsfiddle
main.ng-leave {
transition: 0.25s ease all;
opacity: 1;
transform: translateX(0);
}
main.ng-leave.ng-leave-active {
opacity: 0;
transform: translateX(-275px);
}
(it should work like this)
This technically works locally but the this transition will never occur since I can't route to it

Angularjs auto-hide navigation

i would like to make my navigation menu that is fixed to the top of my page to auto-hide the same way you can make the taskbar in windows hide when you have "auto-hide taskbar" enabled
I would like it to hide and then when you move your mouse close to the top of the screen for it to become visible again and then hide again when you move your mouse away from the top.
What is the best way i can make this happen?
Thanks in advance for your answers!
So many different ways to do this but a very quick think about it ...
You have your HTML nav bar...
<div nav-directive>
<div class="nag" ng-class="{ 'visible': visible }"></div>
</div>
Directive
.directive('navDirective', function() {
return {
restrict: 'EA',
link: function(scope, el) {
scope.visible = false;
el.bind('mouseover', function() {
scope.visible = true;
// You shouldn't do but may need a scope apply here, not sure...
});
el.bind('mouseout', function() {
scope.visible = false;
// again not sure scope apply?
});
}
}
});
This will get you your basic adding and removing the class visible.
Then you can use some CSS3 to get some sliding motion in.
.nav {
top: 0px;
position: absolute;
transition: transform 1s ease-in;
transform: translate(-100%, 0);
}
.nav.visible {
transform: translate(0, 0);
}

Angular animate not working correctly on first run when element is initially hidden

I am wiring up a status bar on my angular app, the purpose is when a request is made to the server the bar will show the response message, will have a background colour to denote success or error, and if it was successful to hide after a few seconds.
What I am seeing is that the first time this logic is run through after loading the page the animations are not run (both the fade in and timed fadeout fail to run), but only if the status bar element is initially hidden, if I set the ng-show variable to true on page load all the animations work as expected.
I did inspect the source via chrome's developer tools and during this first run the div has these classes alert-bar ng-hide-remove ng-hide-remove-active alert-bar-success ng-animate ng-hide after the animation should have been finished. When the animation does work the only classes present are alert-bar alert-bar-success ng-animate ng-hide.
The HTML:
<div class="alert-bar" ng-show="response.show" ng-class="(response.result == true) ? 'alert-bar-success' : 'alert-bar-danger'">
<div class="container">
<label>Message: {{response.message}}</label>
</div>
</div>
The CSS:
.alert-bar {
width: 100%;
margin-top: -20px;
margin-bottom: 20px;
}
.alert-bar-success {
background-color: #5cb85c;
border-color: #4cae4c;
color: #ffffff;
}
.alert-bar-danger {
color: #ffffff;
background-color: #d9534f;
border-color: #d43f3a;
}
.alert-bar.ng-hide-add, .alert-bar.ng-hide-remove {
-webkit-transition:all linear 0.3s;
-moz-transition:all linear 0.3s;
-o-transition:all linear 0.3s;
transition:all linear 0.3s;
display:block!important;
}
.alert-bar.ng-hide-add.ng-hide-add-active,
.alert-bar.ng-hide-remove {
opacity:0;
}
.alert-bar.ng-hide-add,
.alert-bar.ng-hide-remove.ng-hide-remove-active {
opacity:1;
}
The Controller:
controllers.controller("AppController", ['$scope', '$timeout', function($scope, $timeout) {
$scope.response = {};
$scope.response.received = function(message, result) {
$scope.response.message = message;
$scope.response.result = result;
$scope.response.show = true;
if (result == true) {
$timeout(function () {
$scope.response.show = false;
}, 4000);
}
};
}]);
This happens due to interplay between the animation code applied for both the ng-class and ng-hide directives. The only way I have made things like this work is to use separate <div> elements which are shown/hidden conditionally but that have static classes.
Here is a plunkr that demonstrates splitting the above into two <div> elements to create a working example for the problem in the question:
http://plnkr.co/edit/PFNGkOLKvs8Gx9h1T6Yk?p=preview
Alternatively, you could forego the use of ng-hide/ng-show entirely and use ng-class exclusively.
Edit: see http://plnkr.co/edit/JiLPc6cqiLHR21c64cCy?p=preview for a version that uses ng-class exclusively.
You don't need to use two divs. I guess the simplest solution is just putting animate css into class "ng-hide-add-active" only, not into "ng-hide-add". Like below:
.page-ready-animate.ng-hide-add-active {
-webkit-animation: 0.5s fadeOutDown;
animation: 0.5s fadeOutDown;
}

How do you animate ng-show?

I would like to fade out a UL on ng-show=false. I add this css:
ul {
-webkit-transition: all 2s;
transition: all 2s;
}
.ng-show-remove,
.ng-show-add,
.ng-hide-remove,
.ng-hide-add {
display:block!important;
}
ul.ng-hide {
opacity: .2;
}
But when ng-show is set to false it just instantly disappears. How do I get it to fade out instead of instantly disappearing?
Click one of the li in this fiddle for a demonstration.
I've attached a fiddle solution.
A few things to note:
The angular version you included in your fiddle doesn't support the css animations. You'll need to update to the 1.2 version (which also requires you to include the angular-animate.js file and the ngAnimate module into your app)
var app = angular.module('foo', ['ngAnimate']);
Fiddle.

Can ngAnimate be used without defining CSS3 classes or JavaScript?

Is it possible to use ngAnimate without any CSS3 or JavaScript? Let's say if you simply need to toggle the opacity, can you just do it in the markup?
<div ng-show='foo == 'yes'' ng-animate="show: 'opacity:1', hide: 'opacity:0'" >
</div>
Animation in the browser either needs to happen by (1) letting the browser's rendering engine handle it via CSS, or (2) controlling it yourself with JavaScript. So, somewhere, one of these two things needs to happen.
That said, you could build your own directive that builds the correct CSS and/or JavaScript on the fly and attaches/applies it to the given element, but I believe that using ngAnimate as provided is probably easier.
An example for those coming into ngAnimate for the first time:
HTML:
<div ng-show="foo == 'yes'" ng-animate="{show: 'fade'}"></div>
CSS:
.enter-fade {
-webkit-transition: 1s linear opacity;
-moz-transition: 1s linear opacity;
-o-transition: 1s linear opacity;
transition: 1s linear opacity;
opacity: 0;
}
.enter-fade.enter-fade-active {
opacity: 1;
}
Or, if you're supporting browsers that don't support CSS3 transitions, you can do the transition with JavaScript instead:
myModule.animation('fade', function() {
return {
setup : function(element) {
element.css({'opacity': 0});
},
start : function(element, done, memo) {
element.animate({'opacity': 1}, function() {
done();
});
}
};
});
You can find more information at these great Yearofmoo articles:
Animation in AngularJS
Enhanced Animation in AngularJS

Resources