-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTAnimator.js
74 lines (66 loc) · 1.78 KB
/
TAnimator.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
import * as React from 'react';
import { Text, View, StyleSheet, Animated } from 'react-native';
export default class TAnimator extends React.Component {
animatedValues = [];
constructor(props) {
super(props);
const textArray = props.content.trim().split(' ');
textArray.forEach((_, i) => {
this.animatedValues[i] = new Animated.Value(0);
});
this.textArray = textArray;
}
componentDidMount() {
this.animated()
}
animated = (toValue = 1) => {
const animations = this.textArray.map((_,i) => {
return Animated.timing(this.animatedValues[i],{
toValue,
duration: this.props.duration,
useNativeDriver:true
});
});
Animated.stagger(this.props.duration / 5, animations).start(() => {
if (this.props.onFinish) {
this.props.onFinish();
}
});
}
render() {
return (
<View style={[this.props.style, styles.textContainer]}>
{this.textArray.map((word, index) => {
return(
<Animated.Text key={`${word}-${index}`}
style={[
this.props.textStyle,
{
opacity: this.animatedValues[index],
transform: [
{
translateY: Animated.multiply(
this.animatedValues[index],
new Animated.Value(-5)
)
}
]
}
]
}>
{word}
{`${index < this.textArray.length ? ' ' : ''}`}
</Animated.Text>
)
})}
</View>
)
}
}
const styles = StyleSheet.create({
textContainer: {
flexDirection:'row',
flexWrap: 'wrap',
justifyContent:'center'
}
});