Skip to content

Commit b3423a9

Browse files
KagamiChantomchentw
authored andcommitted
fix(ToastMessage): switch to hosted ReactTransitionEvents
* Original commit: 6aae839 * Original author: @KagamiChan * Closes #108 * Closes #86
1 parent 006736d commit b3423a9

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

src/lib/ToastMessage/animationMixin.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import {
2-
default as ReactTransitionEvents,
3-
} from "react/lib/ReactTransitionEvents";
4-
51
import {
62
default as ReactDOM,
73
} from "react-dom";
@@ -10,6 +6,10 @@ import {
106
default as elementClass,
117
} from "element-class";
128

9+
import {
10+
default as ReactTransitionEvents,
11+
} from "./transitionEvents";
12+
1313
const TICK = 17;
1414
const { toString } = Object.prototype;
1515

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const endEvents = [];
2+
3+
const EVENTS = {
4+
transitionend: {
5+
transition: `transitionend`,
6+
WebkitTransition: `webkitTransitionEnd`,
7+
MozTransition: `mozTransitionEnd`,
8+
msTransition: `MSTransitionEnd`,
9+
OTransition: `oTransitionEnd`,
10+
},
11+
12+
animationend: {
13+
animation: `animationend`,
14+
WebkitAnimation: `webkitAnimationEnd`,
15+
MozAnimation: `mozAnimationEnd`,
16+
msAnimation: `MSAnimationEnd`,
17+
OAnimation: `oAnimationEnd`,
18+
},
19+
};
20+
21+
if (typeof window !== `undefined`) {
22+
const style = document.createElement(`div`).style;
23+
for (let eventType in EVENTS) {
24+
if (!EVENTS.hasOwnProperty(eventType)) {
25+
continue
26+
}
27+
const prefixes = EVENTS[eventType];
28+
for (let styleProp in prefixes) {
29+
if (prefixes.hasOwnProperty(styleProp) && styleProp in style) {
30+
endEvents.push(prefixes[styleProp]);
31+
break;
32+
}
33+
}
34+
}
35+
36+
}
37+
38+
const TransitionEvents = {
39+
addEndEventListener: function(node, eventListener) {
40+
if (endEvents.length === 0) {
41+
setTimeout(eventListener, 0);
42+
return;
43+
}
44+
endEvents.forEach(function(event) {
45+
node.addEventListener(event, eventListener, false);
46+
});
47+
},
48+
49+
removeEndEventListener: function(node, eventListener) {
50+
if (endEvents.length === 0) {
51+
return;
52+
}
53+
endEvents.forEach(function(event) {
54+
node.removeEventListener(event, eventListener, false);
55+
});
56+
},
57+
};
58+
59+
60+
export default TransitionEvents;

0 commit comments

Comments
 (0)