forked from shoutem/animation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimingDriver.js
More file actions
44 lines (42 loc) · 1 KB
/
Copy pathTimingDriver.js
File metadata and controls
44 lines (42 loc) · 1 KB
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
import {
Animated,
Easing,
} from 'react-native';
/**
* Animation driver that creates animated value changed with time.
* Pass instance to any @shoutem/animation animation to run it
* e.g.:
* driver = new TimingDriver({
* duration: 400 // 250 by default,
* easing: Easing.inOut // Easing.cubic is passed by default
* delay: 200 // 0 by default
* });
* return (
* <FadeIn driver={driver}>
* <Text>I'm fading in</Text>
* </FadeIn>
* );
* ...
* Check
* http://facebook.github.io/react-native/releases/0.30/docs/animations.html#core-api
* for animation options
*/
export class TimingDriver {
constructor(options) {
this.animationOptions = Object.assign({
easing: Easing.cubic,
duration: 250,
}, options);
this.value = new Animated.Value(0);
this.runTimer = this.runTimer.bind(this);
}
runTimer(endValue, onFinish) {
Animated.timing(
this.value,
{
toValue: endValue,
...this.animationOptions,
}
).start(onFinish);
}
}