-
Notifications
You must be signed in to change notification settings - Fork 41
Removing Deprecated Neon-Animation Dependency #160
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
--> | ||
|
||
<link rel="import" href="../polymer/polymer.html"> | ||
<link rel="import" href="../neon-animation/neon-animation-runner-behavior.html"> | ||
<link rel="import" href="../paper-dialog-behavior/paper-dialog-behavior.html"> | ||
<link rel="import" href="../paper-dialog-behavior/paper-dialog-shared-styles.html"> | ||
<!-- | ||
|
@@ -43,19 +42,11 @@ <h2>Header</h2> | |
### Animations | ||
|
||
Set the `entry-animation` and/or `exit-animation` attributes to add an animation when the dialog | ||
is opened or closed. See the documentation in | ||
[PolymerElements/neon-animation](https://github.com/PolymerElements/neon-animation) for more info. | ||
is opened or closed. Included in the component are fade-in-animation (and out), scale-up-animation. | ||
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. nit: can you list the animation explicitly here?
|
||
|
||
For example: | ||
|
||
<link rel="import" href="components/neon-animation/animations/scale-up-animation.html"> | ||
<link rel="import" href="components/neon-animation/animations/fade-out-animation.html"> | ||
|
||
<paper-dialog entry-animation="scale-up-animation" | ||
exit-animation="fade-out-animation"> | ||
<h2>Header</h2> | ||
<div>Dialog body</div> | ||
</paper-dialog> | ||
@deprecated This animation was based on the deprecated Neon-Animation component. It now | ||
uses CSS Web Animations. This change reduces code size, and uses the platform. Any CSS3 animation | ||
class can be used. | ||
|
||
### Accessibility | ||
|
||
|
@@ -70,40 +61,206 @@ <h2>Header</h2> | |
|
||
<dom-module id="paper-dialog"> | ||
<template> | ||
<style include="paper-dialog-shared-styles"></style> | ||
<style include="paper-dialog-shared-styles"> | ||
@keyframes keyFrameScaleUp { | ||
0% { | ||
transform: scale(0.0); | ||
} | ||
100% { | ||
transform: scale(1.0); | ||
} | ||
} | ||
|
||
@keyframes keyFrameFadeInOpacity { | ||
0% { | ||
opacity: 0; | ||
} | ||
100% { | ||
opacity: 1; | ||
} | ||
} | ||
|
||
@keyframes keyFrameFadeOutOpacity { | ||
0% { | ||
opacity: 1; | ||
} | ||
100% { | ||
opacity: 0; | ||
} | ||
} | ||
|
||
@keyframes keyFrameScaleDown { | ||
0% { | ||
transform: scale(1.0); | ||
} | ||
100% { | ||
transform: scale(0.0); | ||
} | ||
} | ||
|
||
:host(.fade-in-animation) { | ||
opacity: 0; | ||
animation-delay: 0; | ||
animation-name: keyFrameFadeInOpacity; | ||
animation-iteration-count: 1; | ||
animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1); | ||
animation-duration: var(--paper-dialog-duration-in, 500ms); | ||
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'd avoid exposing new css custom properties/mixins for now, as the user can decide to redefine all of this by doing: <style>
.fade-in-animation {
/* my overrides */
animation-duration: 1s;
}
<paper-dialog entry-animation="fade-in-animation"> |
||
animation-fill-mode: forwards; | ||
@apply --paper-dialog-animation; | ||
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'd remove this for now (same reasoning as above) |
||
} | ||
|
||
:host(.fade-out-animation) { | ||
opacity: 1; | ||
animation-delay: 0; | ||
animation-name: keyFrameFadeOutOpacity; | ||
animation-iteration-count: 1; | ||
animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1); | ||
animation-duration: var(--paper-dialog-duration-out, 1500ms); | ||
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'd remove this for now (same reasoning as above), also the default value should be 500ms as for the other ones. |
||
animation-fill-mode: forwards; | ||
@apply --paper-dialog-animation; | ||
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'd remove this for now (same reasoning as above) |
||
} | ||
|
||
:host(.scale-up-animation) { | ||
transform: scale(0); | ||
opacity: 1; | ||
animation-delay: 0; | ||
animation-name: keyFrameScaleUp; | ||
animation-iteration-count: 1; | ||
animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1); | ||
animation-duration: var(--paper-dialog-duration-in, 500ms); | ||
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'd remove this for now (same reasoning as above) |
||
animation-fill-mode: forwards; | ||
@apply --paper-dialog-animation; | ||
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'd remove this for now (same reasoning as above) |
||
} | ||
|
||
.scale-down-animation { | ||
transform: scale(1); | ||
opacity: var(--paper-dialog-opacity, 0.9); | ||
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'd remove this for now (same reasoning as above), and set it to 1 |
||
animation-delay: 0; | ||
animation-name: keyFrameScaleDown; | ||
animation-iteration-count: 1; | ||
animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1); | ||
animation-duration: var(--paper-dialog-duration-out, 500ms); | ||
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'd remove this for now (same reasoning as above) |
||
animation-fill-mode: forwards; | ||
@apply --paper-dialog-animation; | ||
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'd remove this for now (same reasoning as above) |
||
} | ||
|
||
</style> | ||
<slot></slot> | ||
</template> | ||
</dom-module> | ||
|
||
<script> | ||
Polymer({ | ||
is: 'paper-dialog', | ||
|
||
behaviors: [ | ||
Polymer.PaperDialogBehavior, | ||
Polymer.NeonAnimationRunnerBehavior | ||
], | ||
|
||
listeners: { | ||
'neon-animation-finish': '_onNeonAnimationFinish' | ||
}, | ||
|
||
_renderOpened: function() { | ||
this.cancelAnimation(); | ||
this.playAnimation('entry'); | ||
}, | ||
|
||
_renderClosed: function() { | ||
this.cancelAnimation(); | ||
this.playAnimation('exit'); | ||
}, | ||
|
||
_onNeonAnimationFinish: function() { | ||
if (this.opened) { | ||
this._finishRenderOpened(); | ||
} else { | ||
this._finishRenderClosed(); | ||
Polymer({ | ||
is: 'paper-dialog', | ||
|
||
behaviors: [ | ||
Polymer.PaperDialogBehavior | ||
], | ||
|
||
listeners: { | ||
'webkitAnimationEnd': '_onAnimationEnd', | ||
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. should this be |
||
}, | ||
|
||
properties: { | ||
/** | ||
* Set Entry Animation | ||
*/ | ||
entryAnimation: { | ||
value: "fade-in-animation", | ||
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. Would remove this default value, as it forces animations for all paper-dialogs |
||
type: String | ||
}, | ||
/** | ||
* Set Exit Animation | ||
*/ | ||
exitAnimation: { | ||
type: String | ||
}, | ||
_showing: { | ||
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. this should not be required, as it's enough to use |
||
type: Boolean, | ||
value: false | ||
} | ||
}, | ||
|
||
/** | ||
* @return {void} | ||
*/ | ||
attached: function () { | ||
this._addListeners(); | ||
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. You shouldn't require to add/remove listeners on attached/detached: when a node is detached, it won't fire |
||
}, | ||
|
||
/** | ||
* @return {void} | ||
*/ | ||
detached: function () { | ||
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. can remove |
||
this._removeListeners(); | ||
}, | ||
|
||
_renderOpened: function () { | ||
this._showing = true; | ||
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. can remove (we can use |
||
this.cancelAnimation(); | ||
this._entryAnimation(); | ||
}, | ||
|
||
_renderClosed: function () { | ||
this._showing = false; | ||
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. can remove (we can use |
||
this.cancelAnimation(); | ||
this._exitAnimation(); | ||
}, | ||
|
||
_addListeners: function () { | ||
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. can remove |
||
this.listen(this, 'animationend', '_onAnimationEnd'); | ||
}, | ||
|
||
_removeListeners: function () { | ||
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. can remove |
||
this.unlisten(this, 'animationend', '_onAnimationEnd'); | ||
}, | ||
|
||
cancelAnimation: function () { | ||
// Short-cut and cancel all animations and hide | ||
this.classList.remove(this.entryAnimation); | ||
this.classList.remove(this.exitAnimation); | ||
}, | ||
|
||
_entryAnimation: function () { | ||
if (!this.entryAnimation) { | ||
this._onAnimationEnd(); | ||
} else { | ||
this.classList.add(this.entryAnimation); | ||
// If not animation _onAnimationEnd will not be called and will fail to change state | ||
if (this._isSetAnimationValid()) { | ||
this._onAnimationEnd(); | ||
} | ||
|
||
} | ||
}, | ||
|
||
_exitAnimation: function () { | ||
if (!this.exitAnimation) { | ||
this._onAnimationEnd(); | ||
} else { | ||
this.classList.add(this.exitAnimation); | ||
// If not animation _onAnimationEnd will not be called and will fail to change state | ||
if (this._isSetAnimationValid()) { | ||
this._onAnimationEnd(); | ||
} | ||
} | ||
}, | ||
|
||
_onAnimationEnd: function () { | ||
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.
We need to handle the case here. Also, we need to always remove the classes before calling finishRenderOpened/Closed: _onAnimationEnd: function (event) {
if (event.target !== this) {
return;
}
// Removes animation classes.
this.cancelAnimation();
if (!this.opened) {
this._finishRenderClosed();
} else {
this._finishRenderOpened();
}
}, |
||
// If no longer showing add class hidden to completely hide dialog | ||
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 (!this._showing) { | ||
this.classList.remove(this.exitAnimation); | ||
this._finishRenderClosed(); | ||
} else { | ||
this._finishRenderOpened(); | ||
} | ||
}, | ||
|
||
_isSetAnimationValid: function () { | ||
// If CSS Class does not have animation-name considered not be an animation | ||
var style = window.getComputedStyle(this); | ||
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. It would be worth to check for |
||
return (style.getPropertyValue("animation-name") === "none") | ||
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. nit: |
||
} | ||
} | ||
}); | ||
</script> | ||
|
||
}); | ||
</script> |
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.
(missed this) we should remove it from the 1.x variant too (line 42)