-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added animations for show/hide #20
Changes from all commits
d47bc8b
e5273b0
ab2ac11
1ede56c
16fdcd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import velocity from 'velocity-animate'; | ||
import 'velocity-animate/velocity.ui'; | ||
import { animationEvent } from 'aurelia-templating'; | ||
import { aureliaHideClassName} from 'aurelia-templating-resources/aurelia-hide-style'; | ||
import {DOM, PLATFORM} from 'aurelia-pal'; | ||
|
||
/** | ||
|
@@ -31,7 +32,9 @@ export class VelocityAnimator { | |
*/ | ||
effects: any = { | ||
':enter': 'fadeIn', | ||
':leave': 'fadeOut' | ||
':leave': 'fadeOut', | ||
':show': 'fadeIn', | ||
':hide': 'fadeOut' | ||
}; | ||
|
||
/** | ||
|
@@ -239,8 +242,13 @@ export class VelocityAnimator { | |
* @returns Resolved when the animation is done | ||
*/ | ||
removeClass(element: HTMLElement, className: string): Promise<boolean> { | ||
element.classList.remove(className); | ||
return Promise.resolve(false); | ||
if (className === aureliaHideClassName && element.getAttribute('anim-show')) { | ||
element.classList.remove(className); | ||
return this.stop(element, true)._runElementAnimation(element, ':show', undefined, 'show'); | ||
} else { | ||
element.classList.remove(className); | ||
return Promise.resolve(false); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -250,8 +258,14 @@ export class VelocityAnimator { | |
* @returns Resolved when the animation is done | ||
*/ | ||
addClass(element: HTMLElement, className: string): Promise<boolean> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that enter/leave do accept an options attribute, is that not needed for remove/add? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it is not used when templating calls enter/leave. |
||
element.classList.add(className); | ||
return Promise.resolve(false); | ||
if (className === aureliaHideClassName && element.getAttribute('anim-hide')) { | ||
return this.stop(element, true)._runElementAnimation(element, ':hide', undefined, 'hide').then(() => { | ||
element.classList.add(className); | ||
}); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the else block is not really needed since the if contains a return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quite true. :-) |
||
element.classList.add(className); | ||
return Promise.resolve(false); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -327,6 +341,18 @@ export class VelocityAnimator { | |
attrOpts = leave.options; | ||
break; | ||
|
||
case ':show': | ||
let show = element.animations.show; | ||
name = show.properties; | ||
attrOpts = show.options; | ||
break; | ||
|
||
case ':hide': | ||
let hide = element.animations.hide; | ||
name = hide.properties; | ||
attrOpts = hide.options; | ||
break; | ||
|
||
default: | ||
if (!this.effects[this.resolveEffectAlias(name)]) throw new Error(`${name} animation is not supported.`); | ||
} | ||
|
@@ -351,6 +377,8 @@ export class VelocityAnimator { | |
el.animations = {}; | ||
el.animations.enter = this._parseAttributeValue(el.getAttribute('anim-enter')) || this.enterAnimation; | ||
el.animations.leave = this._parseAttributeValue(el.getAttribute('anim-leave')) || this.leaveAnimation; | ||
el.animations.show = this._parseAttributeValue(el.getAttribute('anim-show')) || undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the animation for leave/show is not defined shouldn't we use defaults like for enter/leave? See line 22/23 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I initially did that, but reconsidered. Then enter/leave effects are opt-in by adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok let's keep it the way it is |
||
el.animations.hide = this._parseAttributeValue(el.getAttribute('anim-hide')) || undefined; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the function return type be
Promise<boolean|VelocityAnimator>
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no TypeScript expert. However,
_runElementAnimation()
returnsPromise<any>
, so then it could just as well bePromise<any>
forremoveClass()
. But wouldn't that violate the Animator interface definition, which hasPromise<bool>
? Should I perhaps add a.then()
that returns a boolean on success?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The then approach is the way to go 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just make sure to add a catch as well in case something goes wrong