forked from react-native-oh-library/RNOHDCS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnimateNumberDemo.tsx
72 lines (69 loc) · 2.42 KB
/
AnimateNumberDemo.tsx
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
import React, { useState } from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
import AnimateNumber from 'react-native-animate-number';
const App = () => {
const [value, setValue] = useState(0);
const onPress = () => { setValue(100) };
const [finish, setFinish] = useState('');
const [progress, setProgress] = useState('');
const onProgress = () => { setProgress('动画正在更新...') };
const onFinish = () => { setFinish('动画更新完成') }
return (
<View style={styles.container}>
<View style={styles.button}>
<Button
title={'点击开始动画'}
onPress={onPress}
/>
</View>
<Text style={styles.row}>
<Text>linear:</Text>
<AnimateNumber value={value} timing="linear" countBy={1} interval={150} />
</Text>
<Text style={styles.row}>
<Text>easeOut:</Text>
<AnimateNumber value={value} timing="easeOut" countBy={1} interval={150} />
</Text>
<Text style={styles.row}>
<Text>easeIn:</Text>
<AnimateNumber value={value} timing="easeIn" countBy={1} interval={150} />
</Text>
<Text style={styles.row}>
<Text>steps:</Text>
<AnimateNumber value={value} steps={5} interval={2000} />
</Text>
<Text style={styles.row}>
<Text>Formate Example:</Text>
<AnimateNumber value={value} countBy={1} interval={150} formatter={(val) => {
return '$ ' + parseFloat(val).toFixed(2)
}} />
</Text>
<Text style={styles.row}>
<Text>{progress}</Text>
</Text>
<Text style={styles.row}>
<AnimateNumber value={30} countBy={5} interval={600} onProgress={onProgress} onFinish={onFinish} />
</Text>
<Text style={styles.row}>
<Text>{finish}</Text>
</Text>
</View>
);
};
const styles = StyleSheet.create({
container: {
justifyContent: "center",
flex: 1,
alignItems: "center"
},
row: {
fontSize: 20,
fontWeight: 'bold',
flexDirection: "row",
marginBottom: 20
},
button: {
marginBottom: 20
},
});
export default App;