Skip to content
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

Fix animation bugs #321

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/addons/transitions/ReactTransitionEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,29 @@
var ExecutionEnvironment = require('ExecutionEnvironment');

var EVENT_NAME_MAP = {
'transition': ['animationend', 'transitionend'],
'WebkitTransition': ['webkitAnimationEnd', 'webkitTransitionEnd'],
'MozTransition': ['mozAnimationEnd', 'mozTransitionEnd'],
'OTransition': ['oAnimationEnd', 'oTransitionEnd'],
'msTransition': ['MSAnimationEnd', 'MSTransitionEnd']
// Transition events
'transition': 'transitionend',
'WebkitTransition': 'webkitTransitionEnd',
'MozTransition': 'mozTransitionEnd',
'OTransition': 'oTransitionEnd',
'msTransition': 'MSTransitionEnd',

// Animation events
'animation': 'animationend',
'WebkitAnimation': 'webkitAnimationEnd',
'MozAnimation': 'mozAnimationEnd',
'OAnimation': 'oAnimationEnd',
'msAnimation': 'MSAnimationEnd'
};

var endEvents = null;
var endEvents = [];

function detectEvents() {
var testEl = document.createElement('div');
var style = testEl.style;
for (var styleName in EVENT_NAME_MAP) {
if (styleName in style) {
endEvents = EVENT_NAME_MAP[styleName];
return;
endEvents.push(EVENT_NAME_MAP[styleName]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're going to double listen in webkit. We should probably do these separately and stick with the early exit.

'transition' in testEl.style // true
'WebkitTransition' in testEl.style // true

}
}
}
Expand All @@ -60,7 +67,7 @@ function removeEventListener(node, eventName, eventListener) {

var ReactTransitionEvents = {
addEndEventListener: function(node, eventListener) {
if (!endEvents) {
if (endEvents.length === 0) {
// If CSS transitions are not supported, trigger an "end animation"
// event immediately.
window.setTimeout(eventListener, 0);
Expand All @@ -72,7 +79,7 @@ var ReactTransitionEvents = {
},

removeEndEventListener: function(node, eventListener) {
if (!endEvents) {
if (endEvents.length === 0) {
return;
}
endEvents.forEach(function(endEvent) {
Expand Down
3 changes: 0 additions & 3 deletions src/addons/transitions/ReactTransitionableChild.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ var ReactTransitionableChild = React.createClass({

queueClass: function(className) {
this.classNameQueue.push(className);
this.runNextTick(this.flushClassNameQueue);
},

runNextTick: function() {
if (this.props.runNextTick) {
this.props.runNextTick(this.flushClassNameQueue);
return;
Expand Down