-
Notifications
You must be signed in to change notification settings - Fork 0
/
Animated3.js
93 lines (86 loc) · 2.2 KB
/
Animated3.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
86
87
88
89
90
91
92
93
import React, {
Component
} from 'react';
import {
Animated,
Easing,
Image,
StyleSheet,
Text,
View,
Dimensions,
} from 'react-native';
export default class Animated3 extends React.Component {
constructor(props: any) {
super(props);
this.state = {
fadeInOpacity: new Animated.Value(0),
rotation: new Animated.Value(0),
fontSize: new Animated.Value(0),
};
//this.startAnimation = this.startAnimation.bind(this);
}
startAnimation = () => {
var timing = Animated.timing;
var that = this;
this.state.fadeInOpacity.setValue(0);
this.state.rotation.setValue(0);
this.state.fontSize.setValue(0);
Animated.parallel(['fadeInOpacity', 'rotation', 'fontSize'].map(property => {
return timing(this.state[property], {
toValue: 1,
duration: 1000,
easing: Easing.linear,
//delay: 500,
});
})).start(()=>{
this.timer = setTimeout(
() => {
that.startAnimation();
}
,800);
});
};
componentDidMount() {
this.startAnimation();
}
componentWillUnmount() {
// 如果存在this.timer,则使用clearTimeout清空。
// 如果你使用多个timer,那么用多个变量,或者用个数组来保存引用,然后逐个clear
this.timer && clearTimeout(this.timer);
}
render(): ReactElement {
return ( < Animated.View style = {
[styles.demo, {
opacity: this.state.fadeInOpacity,
transform: [{
rotateZ: this.state.rotation.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg']
})
}]
}]
} >
< Animated.Text style = {
{
fontSize: this.state.fontSize.interpolate({
inputRange: [0, 1],
outputRange: [12, 26]
})
}
} > 我骑着七彩祥云出现了 < /Animated.Text>
</Animated.View>
);
}
}
var styles = StyleSheet.create({
demo: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'white',
},
text: {
fontSize: 30
}
});