This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathTransitions.js
85 lines (72 loc) · 2.42 KB
/
Transitions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'use strict';
var { Mixin, easingTypes } = require('react-tween-state');
var Transitions = Object.assign(Mixin, {
getInitialState() {
return {
isTransitioning: false,
tweenQueue: [],
tweenProperties: [],
};
},
transition(property, options) {
this.setState({isTransitioning: true});
// Add the property to the list of tweenProperties if it isn't already there
if (this.state.tweenProperties.indexOf(property) === -1) {
// Ugly, pushing it directly, but if I clone and setState then only one property
// will be registered at a time and it interferes with multiple tweens
this.state.tweenProperties.push(property);
}
// If no initial value is given, use the current value in the state
var begin = (typeof options.begin === 'undefined' ? this.state[property] : options.begin);
this.tweenState(property, {
easing: options.easing || easingTypes.easeInOutQuad,
duration: options.duration || 300,
delay: options.delay,
beginValue: begin,
endValue: options.end,
onEnd: (() => {
// Perform on next tick because animations are removed from tweenQueue after onEnd is called
requestAnimationFrame(() => {
// If all tweens are done, finish transitioning
if (!this.state.tweenQueue.length) {
this.setState({isTransitioning: false});
}
// Option to reset the state value to the initial value
if (options.reset) {
if (options.reset) {
this.state[property] = begin;
} else {
this.state[property] = options.reset;
}
}
// Custom onEnd callback
if (options.onEnd) {
options.onEnd();
}
});
}),
});
},
transitionStyles(propertySet) {
if (typeof propertySet === 'undefined') {
propertySet = [];
}
var result = {};
this.state.tweenProperties.forEach((property) => {
if (propertySet.length === 0 || propertySet.indexOf(property) > -1) {
var value, tweeningValue = this.getTweeningValue(property);
if (typeof tweeningValue === 'undefined' || tweeningValue === null) {
value = this.state[property];
} else {
value = tweeningValue;
}
result[property] = value;
}
});
return result;
}
});
module.exports = {
Mixin: Transitions,
Easings: easingTypes,
};