forked from guangqiang-liu/react-native-toastAndLoading
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
150 lines (143 loc) · 3.72 KB
/
App.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* Created by guangqiang on 2017/12/12.
*/
import React, { Component } from 'react'
import {
StyleSheet,
Text,
View,
TouchableOpacity,
Dimensions
} from 'react-native'
import {Toast} from './Toast'
import {Loading} from './Loading'
const width = Dimensions.get('window').width
export default class App extends Component {
toast(type) {
switch (type) {
case 'show':
Toast.show('这是show类型')
break
case 'showLong':
Toast.showLong('这是showLong类型')
break
case 'showSuccess':
Toast.showSuccess('这是showSuccess类型')
break
case 'showSuccessCallback':
Toast.showSuccess('这是showSuccessCallback类型', () => alert('回调成功!'))
break
case 'showLongSuccess':
Toast.showLongSuccess('这是showLongSuccess类型')
break
case 'showLongSuccessCallback':
Toast.showLongSuccess('这是showLongSuccessCallback类型', () => alert('回调成功!'))
break
case 'showWarning':
Toast.showWarning('这是showWarning类型')
break
case 'showError':
Toast.showError('这是showError类型')
break
}
}
hud(type) {
if (type === 'show') {
Loading.show()
setTimeout(function () {
Loading.hidden()
}, 5000)
} else {
Loading.hidden()
}
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Toast</Text>
<TouchableOpacity
style={styles.text}
onPress={() => this.toast('show')}
>
<Text>show</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.text}
onPress={() => this.toast('showLong')}
>
<Text>showLong</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.text}
onPress={() => this.toast('showSuccess')}
>
<Text>showSuccess</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.text}
onPress={() => this.toast('showSuccessCallback')}
>
<Text>showSuccess带函数回调</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.text}
onPress={() => this.toast('showLongSuccess')}
>
<Text>showLongSuccess</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.text}
onPress={() => this.toast('showLongSuccessCallback')}
>
<Text>showLongSuccess带函数回调</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.text}
onPress={() => this.toast('showWarning')}
>
<Text>showWarning</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.text}
onPress={() => this.toast('showError')}
>
<Text>showError</Text>
</TouchableOpacity>
<Text style={styles.welcome}>HUD</Text>
<TouchableOpacity
style={styles.text}
onPress={() => this.hud('show')}
>
<Text>showHud</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.text}
onPress={() => this.hud('hidden')}
>
<Text>hiddenHud</Text>
</TouchableOpacity>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
text: {
width: width - 40,
paddingVertical: 6,
backgroundColor: '#ccc',
marginVertical: 10,
justifyContent: 'center',
alignItems: 'center'
}
})