Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Commit

Permalink
feat(Animate): add support for maybe correct ng1 css animation classes
Browse files Browse the repository at this point in the history
 - roughly approximate by adding {name}-add {name}-add-active {name}-remove {name}-remove-active classes during animation.
 - I'm not 100% sure this is correct, but it did work for the sidenav animation. Because the animation stuff is just placeholder waiting for official animation support, this is good enough for me.
  • Loading branch information
justindujardin committed Jan 24, 2016
1 parent 4f847dc commit cb85ae4
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions ng2-material/core/util/animate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
import {TimerWrapper} from "angular2/src/facade/async";

/**
* Provide an API for animating elements with CSS transitions
Expand All @@ -13,30 +14,42 @@ export class Animate {
static enter(el: HTMLElement, cssClass: string): Promise<void> {
DOM.removeClass(el, cssClass);
return new Promise<void>((resolve)=> {
var duration = Animate.getTransitionDuration(el, true);
var callTimeout = setTimeout(() => done(), duration);
var done = () => {
clearTimeout(callTimeout);
removeListener();
resolve();
};
let removeListener = DOM.onAndCancel(el, Animate.TRANSITION_EVENT, done);
DOM.addClass(el, cssClass);
DOM.addClass(el, cssClass + '-add');
TimerWrapper.setTimeout(() => {
var duration = Animate.getTransitionDuration(el, true);
var callTimeout = setTimeout(() => done(), duration);
var done = () => {
DOM.removeClass(el, cssClass + '-add-active');
DOM.removeClass(el, cssClass + '-add');
clearTimeout(callTimeout);
removeListener();
resolve();
};
let removeListener = DOM.onAndCancel(el, Animate.TRANSITION_EVENT, done);
DOM.addClass(el, cssClass + '-add-active');
DOM.addClass(el, cssClass);
}, 1);
});
}

static leave(el: HTMLElement, cssClass: string): Promise<void> {
return new Promise<void>((resolve)=> {
var duration = Animate.getTransitionDuration(el, true);
var callTimeout = setTimeout(() => done(), duration);
DOM.addClass(el, cssClass + '-remove');
TimerWrapper.setTimeout(() => {
var duration = Animate.getTransitionDuration(el, true);
var callTimeout = setTimeout(() => done(), duration);

var done = () => {
clearTimeout(callTimeout);
removeListener();
resolve();
};
let removeListener = DOM.onAndCancel(el, Animate.TRANSITION_EVENT, done);
DOM.removeClass(el, cssClass);
var done = () => {
DOM.removeClass(el, cssClass + '-remove-active');
DOM.removeClass(el, cssClass + '-remove');
clearTimeout(callTimeout);
removeListener();
resolve();
};
let removeListener = DOM.onAndCancel(el, Animate.TRANSITION_EVENT, done);
DOM.addClass(el, cssClass + '-remove-active');
DOM.removeClass(el, cssClass);
}, 1);
});
}

Expand Down

0 comments on commit cb85ae4

Please sign in to comment.