From b2910647a79f81562177e8e41b876f30dde0b73c Mon Sep 17 00:00:00 2001 From: Fin Hopkins Date: Thu, 12 Apr 2018 15:51:43 -0400 Subject: [PATCH] Removes Promise dependency Avoids needing to polyfill for IE11. Also removes from the demo, since that also doesn't work on IE 11 without a polyfill. --- demo/main.jsx | 36 +++++++++++++++----------------- src/velocity-transition-group.js | 30 ++++++++++++++------------ 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/demo/main.jsx b/demo/main.jsx index 40a31c5..1e175e5 100644 --- a/demo/main.jsx +++ b/demo/main.jsx @@ -43,25 +43,23 @@ class Demo extends React.Component { class MainComponent extends React.Component { render() { return ( - -
- - - - - - - - - - - - - - - -
-
+
+ + + + + + + + + + + + + + + +
); } } diff --git a/src/velocity-transition-group.js b/src/velocity-transition-group.js index 4c03eea..6d2527e 100644 --- a/src/velocity-transition-group.js +++ b/src/velocity-transition-group.js @@ -86,26 +86,30 @@ shimCancelAnimationFrame = // Internal wrapper for the transitioned elements. Delegates all child lifecycle events to the // parent VelocityTransitionGroup so that it can co-ordinate animating all of the elements at once. class VelocityTransitionGroupChild extends React.Component { - transitionPromise = Promise.resolve(); + lastState = 'appear'; componentWillEnter = (node, appearing) => { - this.transitionPromise = new Promise(resolve => { - if (appearing) { - this.props.willAppearFunc(node, resolve); - } else { - this.props.willEnterFunc(node, resolve); - } - }); + this.lastState = appearing ? 'appear' : 'enter'; }; - componentWillExit = node => { - this.transitionPromise = new Promise(resolve => { - this.props.willLeaveFunc(node, resolve); - }); + componentWillExit = () => { + this.lastState = 'exit'; }; + // We trigger our transitions out of endListener because that gives us access to the done callback + // we can use to tell the Transition that the animation has completed. endListener = (node, done) => { - this.transitionPromise.then(done); + switch (this.lastState) { + case 'appear': + this.props.willAppearFunc(node, done); + break; + case 'enter': + this.props.willEnterFunc(node, done); + break; + case 'exit': + this.props.willLeaveFunc(node, done); + break; + } }; componentWillUnmount() {