Skip to content

Commit

Permalink
private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
valdrinkoshi committed Sep 21, 2016
1 parent cd050d3 commit 2b061c3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
5 changes: 2 additions & 3 deletions iron-animated-overlay-renderer-shared-styles.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
@apply --layout-fixed-top;
@apply --layout-fixed-bottom;
pointer-events: none;
z-index: -1;
background-color: transparent;
opacity: 0;
transition: background-color .2s, opacity .2s;
Expand All @@ -46,12 +47,10 @@

#overlay {
opacity: 0;
transform: translateY(100px);
transition: opacity .2s, transform .2s;
transition: opacity .2s;
}

:host(.opened) #overlay {
transform: translateY(0);
opacity: 1;
}
</style>
Expand Down
16 changes: 9 additions & 7 deletions iron-animated-overlay-renderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
(function() {
'use strict';

const _forceLayout = Symbol();
const _onTransitionEnd = Symbol();


class IronAnimatedOverlayRenderer extends Polymer.IronOverlayRenderer {
static get is() {
return 'iron-animated-overlay-renderer';
Expand All @@ -47,32 +51,30 @@

ready() {
super.ready();
this.$.overlay.addEventListener('transitionend', this.__onTransitionEnd.bind(this));
this.$.overlay.addEventListener('transitionend', this[_onTransitionEnd].bind(this));
}

/**
* Override this, as we need to wait for animation to complete.
* @protected
*/
_renderOpenedChanged() {
this.__forceLayout();
this[_forceLayout]();
this.classList.toggle('opened', this.opened);
}

/**
* Forces layout.
* @private
*/
__forceLayout() {
[_forceLayout]() {
return this.offsetWidth;
}

/**
* Ends the animation.
* @private
*/
__onTransitionEnd(event) {
if (event.composedPath()[0] === this.$.overlay) {
[_onTransitionEnd](event) {
if (event.target === this.$.overlay) {
this._finishRenderOpenedChanged();
}
}
Expand Down
42 changes: 22 additions & 20 deletions iron-overlay-renderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
(function() {
'use strict';

const _openedChanged = Symbol();
const _startRenderOpenedChanged = Symbol();

class IronOverlayRenderer extends Polymer.Element {

static get is() {
Expand All @@ -67,7 +70,7 @@
*/
opened: {
type: Boolean,
observer: '_openedChanged'
observer: _openedChanged
},

/**
Expand All @@ -88,11 +91,12 @@
this.style.display = 'none';
// For a performant transition from open to close and close to open.
this.__transitionRaf = null;
this[_startRenderOpenedChanged] = this[_startRenderOpenedChanged].bind(this);
}

connectedCallback() {
super.connectedCallback();
this.opened && this._openedChanged(this.opened);
this.opened && this[_openedChanged](this.opened);
}

disconnectedCallback() {
Expand All @@ -103,22 +107,6 @@
}
}

/**
* @param {boolean} opened
* @protected
*/
_openedChanged(opened) {
// Defer any animation-related code on attached
// (_openedChanged gets called again on attached).
if (!this.isConnected) {
return;
}

this._setTransitioning(true);
this.__transitionRaf && window.cancelAnimationFrame(this.__transitionRaf);
this.__transitionRaf = window.requestAnimationFrame(this.__startRenderOpenedChanged.bind(this));
}

/**
* Tasks to be performed to actually open/close. Override this to play
* animations, and call `_finishRenderOpenedChanged()` when those are done.
Expand All @@ -139,11 +127,25 @@
this._setTransitioning(false);
}

/**
* @param {boolean} opened
*/
[_openedChanged](opened) {
// Defer any animation-related code on attached
// (_openedChanged gets called again on attached).
if (!this.isConnected) {
return;
}

this._setTransitioning(true);
this.__transitionRaf && window.cancelAnimationFrame(this.__transitionRaf);
this.__transitionRaf = window.requestAnimationFrame(this[_startRenderOpenedChanged]);
}

/**
* Starts the update from open to closed & viceversa.
* @private
*/
__startRenderOpenedChanged() {
[_startRenderOpenedChanged]() {
this.__transitionRaf = null;
// Ensure it is displayed.
if (this.opened) {
Expand Down

0 comments on commit 2b061c3

Please sign in to comment.