Skip to content

Commit

Permalink
Fix transition end detection for Android
Browse files Browse the repository at this point in the history
Some Android versions have the "transition" and "animation" properties
set on element style objects despite not supporting un-prefxied animations
and transitions.  This change adds an additional sanity check to make sure
the correct event handlers are added for transition groups.
  • Loading branch information
marcins committed Apr 25, 2014
1 parent 28820e0 commit cc56629
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/addons/transitions/ReactTransitionEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

var ExecutionEnvironment = require('ExecutionEnvironment');

/**
* EVENT_NAME_MAP is used to determine which event fired when a
* transition/animation ends, based on the style property used to
* define that event.
*/
var EVENT_NAME_MAP = {
transitionend: {
'transition': 'transitionend',
Expand All @@ -43,6 +48,20 @@ var endEvents = [];
function detectEvents() {
var testEl = document.createElement('div');
var style = testEl.style;

// On some platforms, in particular some releases of Android 4.x,
// the un-prefixed "animation" and "transition" properties are defined on the
// style object but the events that fire will still be prefixed, so we need
// to check if the un-prefixed events are useable, and if not remove them
// from the map
if (!('AnimationEvent' in window)) {
delete EVENT_NAME_MAP.animationend.animation;
}

if (!('TransitionEvent' in window)) {
delete EVENT_NAME_MAP.transitionend.transition;
}

for (var baseEventName in EVENT_NAME_MAP) {
var baseEvents = EVENT_NAME_MAP[baseEventName];
for (var styleName in baseEvents) {
Expand Down

0 comments on commit cc56629

Please sign in to comment.