|
@@ -1,6 +1,227 @@
|
1
|
1
|
# react-native-smart-loading-spinner-overlay
|
2
|
2
|
|
|
3
|
+[![npm](https://img.shields.io/npm/v/react-native-smart-loading-spinner-overlay.svg)](https://www.npmjs.com/package/react-native-smart-loading-spinner-overlay)
|
|
4
|
+[![npm](https://img.shields.io/npm/dm/react-native-smart-loading-spinner-overlay.svg)](https://www.npmjs.com/package/react-native-smart-loading-spinner-overlay)
|
|
5
|
+[![npm](https://img.shields.io/npm/dt/react-native-smart-loading-spinner-overlay.svg)](https://www.npmjs.com/package/react-native-smart-loading-spinner-overlay)
|
|
6
|
+[![npm](https://img.shields.io/npm/l/react-native-smart-loading-spinner-overlay.svg)](https://github.com/react-native-component/react-native-smart-loading-spinner-overlay/blob/master/LICENSE)
|
|
7
|
+
|
3
|
8
|
A smart loading spinner overlay for React Native apps, written in JS for cross-platform support.
|
4
|
9
|
It works on iOS and Android.
|
5
|
10
|
|
6
|
11
|
This component is compatible with React Native 0.25 and newer.
|
|
12
|
+
|
|
13
|
+## Preview
|
|
14
|
+
|
|
15
|
+![react-native-smart-loading-spinner-overlay-preview-ios][1]
|
|
16
|
+![react-native-smart-loading-spinner-overlay-preview-android][2]
|
|
17
|
+
|
|
18
|
+## Installation
|
|
19
|
+
|
|
20
|
+```
|
|
21
|
+npm install react-native-smart-loading-spinner-overlay --save
|
|
22
|
+```
|
|
23
|
+
|
|
24
|
+## Full Demo
|
|
25
|
+
|
|
26
|
+see [ReactNativeComponentDemos][0]
|
|
27
|
+
|
|
28
|
+## Usage
|
|
29
|
+
|
|
30
|
+Install the loading-spinner-overlay from npm with `npm install react-native-smart-loading-spinner-overlay --save`.
|
|
31
|
+Then, require it from your app's JavaScript files with `import loading-spinner-overlay from 'react-native-smart-loading-spinner-overlay'`.
|
|
32
|
+
|
|
33
|
+```js
|
|
34
|
+
|
|
35
|
+import React, {
|
|
36
|
+ Component,
|
|
37
|
+} from 'react'
|
|
38
|
+import {
|
|
39
|
+ View,
|
|
40
|
+} from 'react-native'
|
|
41
|
+
|
|
42
|
+import Button from 'react-native-smart-button'
|
|
43
|
+import TimerEnhance from 'react-native-smart-timer-enhance'
|
|
44
|
+import Toast from 'react-native-smart-loading-spinner-overlay'
|
|
45
|
+
|
|
46
|
+class LoadingSpinnerOverLayDemo extends Component {
|
|
47
|
+
|
|
48
|
+ constructor(props) {
|
|
49
|
+ super(props)
|
|
50
|
+ this.state = {}
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ render() {
|
|
54
|
+ return (
|
|
55
|
+ <View style={{ paddingTop: 64, flex: 1, backgroundColor: '#fff',}}>
|
|
56
|
+ <Button
|
|
57
|
+ onPress={this._showModalLoadingSpinnerOverLay}
|
|
58
|
+ touchableType={Button.constants.touchableTypes.fadeContent}
|
|
59
|
+ style={{margin: 10, height: 40, backgroundColor: 'red', borderRadius: 3, borderWidth: StyleSheet.hairlineWidth, borderColor: 'red', justifyContent: 'center',}}
|
|
60
|
+ textStyle={{fontSize: 17, color: 'white'}}
|
|
61
|
+ >
|
|
62
|
+ show modal loading spinner (模态)
|
|
63
|
+ </Button>
|
|
64
|
+ <Button
|
|
65
|
+ onPress={this._showPartModalLoadingSpinnerOverLay}
|
|
66
|
+ touchableType={Button.constants.touchableTypes.highlight}
|
|
67
|
+ underlayColor={'#C90000'}
|
|
68
|
+ style={{margin: 10, justifyContent: 'center', height: 40, backgroundColor: 'red', borderRadius: 3, borderWidth: StyleSheet.hairlineWidth, borderColor: 'red', justifyContent: 'center',}}
|
|
69
|
+ textStyle={{fontSize: 17, color: 'white'}}
|
|
70
|
+ >
|
|
71
|
+ [part modal]can click header (导航栏允许点击)
|
|
72
|
+ </Button>
|
|
73
|
+ <Button
|
|
74
|
+ onPress={this._showNoModalLoadingSpinnerOverLay}
|
|
75
|
+ touchableType={Button.constants.touchableTypes.blur}
|
|
76
|
+ style={{margin: 10, justifyContent: 'center', height: 40, backgroundColor: 'red', borderRadius: 3, borderWidth: StyleSheet.hairlineWidth, borderColor: 'red', justifyContent: 'center',}}
|
|
77
|
+ textStyle={{fontSize: 17, color: 'white'}}
|
|
78
|
+ >
|
|
79
|
+ show no modal loading spinner (非模态)
|
|
80
|
+ </Button>
|
|
81
|
+
|
|
82
|
+ <Button
|
|
83
|
+ onPress={this._showImmediateLoadingSpinnerOverLayAndImmediateHide}
|
|
84
|
+ touchableType={Button.constants.touchableTypes.fade}
|
|
85
|
+ style={{margin: 10, justifyContent: 'center', height: 40, backgroundColor: 'red', borderRadius: 3, borderWidth: StyleSheet.hairlineWidth, borderColor: 'red', justifyContent: 'center',}}
|
|
86
|
+ textStyle={{fontSize: 17, color: 'white'}}
|
|
87
|
+ >
|
|
88
|
+ show and hide immediately (无渐变)
|
|
89
|
+ </Button>
|
|
90
|
+
|
|
91
|
+ <Button
|
|
92
|
+ onPress={this._showModal_2_LoadingSpinnerOverLay}
|
|
93
|
+ touchableType={Button.constants.touchableTypes.fadeContent}
|
|
94
|
+ style={{margin: 10, height: 40, backgroundColor: 'red', borderRadius: 3, borderWidth: StyleSheet.hairlineWidth, borderColor: 'red', justifyContent: 'center',}}
|
|
95
|
+ textStyle={{fontSize: 17, color: 'white'}}
|
|
96
|
+ >
|
|
97
|
+ custom content (自定义内容)
|
|
98
|
+ </Button>
|
|
99
|
+
|
|
100
|
+ <LoadingSpinnerOverlay
|
|
101
|
+ ref={ component => this._modalLoadingSpinnerOverLay = component }/>
|
|
102
|
+ <LoadingSpinnerOverlay
|
|
103
|
+ ref={ component => this._partModalLoadingSpinnerOverLay = component }
|
|
104
|
+ modal={true}
|
|
105
|
+ marginTop={64}/>
|
|
106
|
+ <LoadingSpinnerOverlay
|
|
107
|
+ ref={ component => this._LoadingSpinnerOverLay = component }
|
|
108
|
+ modal={false}/>
|
|
109
|
+ <LoadingSpinnerOverlay
|
|
110
|
+ ref={ component => this._modalImmediateLoadingSpinnerOverLay = component }/>
|
|
111
|
+ <LoadingSpinnerOverlay
|
|
112
|
+ ref={ component => this._modal_2_LoadingSpinnerOverLay = component }>
|
|
113
|
+ {this._renderActivityIndicator()}
|
|
114
|
+ </LoadingSpinnerOverlay>
|
|
115
|
+ </View>
|
|
116
|
+ )
|
|
117
|
+ }
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+ _showModalLoadingSpinnerOverLay = () => {
|
|
123
|
+ this._modalLoadingSpinnerOverLay.show()
|
|
124
|
+ //simulate http request
|
|
125
|
+ this.setTimeout( () => {
|
|
126
|
+ this._modalLoadingSpinnerOverLay.hide()
|
|
127
|
+ }, 3000)
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ _showPartModalLoadingSpinnerOverLay = () => {
|
|
131
|
+ this._partModalLoadingSpinnerOverLay.show()
|
|
132
|
+ //simulate http request
|
|
133
|
+ this.setTimeout( () => {
|
|
134
|
+ this._partModalLoadingSpinnerOverLay.hide()
|
|
135
|
+ }, 3000)
|
|
136
|
+ }
|
|
137
|
+
|
|
138
|
+ _showNoModalLoadingSpinnerOverLay = () => {
|
|
139
|
+ this._LoadingSpinnerOverLay.show()
|
|
140
|
+ //simulate http request
|
|
141
|
+ this.setTimeout( () => {
|
|
142
|
+ this._LoadingSpinnerOverLay.hide()
|
|
143
|
+ }, 3000)
|
|
144
|
+ }
|
|
145
|
+
|
|
146
|
+ _showImmediateLoadingSpinnerOverLayAndImmediateHide = () => {
|
|
147
|
+ this._modalImmediateLoadingSpinnerOverLay.show({
|
|
148
|
+ duration: 0,
|
|
149
|
+ children: this._renderActivityIndicator(),
|
|
150
|
+ })
|
|
151
|
+ //simulate http request
|
|
152
|
+ this.setTimeout( () => {
|
|
153
|
+ this._modalImmediateLoadingSpinnerOverLay.hide({
|
|
154
|
+ duration: 0,
|
|
155
|
+ })
|
|
156
|
+ }, 3000)
|
|
157
|
+ }
|
|
158
|
+
|
|
159
|
+ _showModal_2_LoadingSpinnerOverLay = () => {
|
|
160
|
+ this._modal_2_LoadingSpinnerOverLay.show()
|
|
161
|
+ //simulate http request
|
|
162
|
+ this.setTimeout( () => {
|
|
163
|
+ this._modal_2_LoadingSpinnerOverLay.hide()
|
|
164
|
+ }, 3000)
|
|
165
|
+ }
|
|
166
|
+
|
|
167
|
+ _renderActivityIndicator() {
|
|
168
|
+ return ActivityIndicator ? (
|
|
169
|
+ <ActivityIndicator
|
|
170
|
+ animating={true}
|
|
171
|
+ color={'#ff0000'}
|
|
172
|
+ size={'small'}/>
|
|
173
|
+ ) : Platform.OS == 'android' ?
|
|
174
|
+ (
|
|
175
|
+ <ProgressBarAndroid
|
|
176
|
+ color={'#ff0000'}
|
|
177
|
+ styleAttr={'small'}/>
|
|
178
|
+
|
|
179
|
+ ) : (
|
|
180
|
+ <ActivityIndicatorIOS
|
|
181
|
+ animating={true}
|
|
182
|
+ color={'#ff0000'}
|
|
183
|
+ size={'small'}/>
|
|
184
|
+ )
|
|
185
|
+ }
|
|
186
|
+
|
|
187
|
+}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+export default TimerEnhance(LoadingSpinnerOverLayDemo)
|
|
191
|
+```
|
|
192
|
+
|
|
193
|
+## Props
|
|
194
|
+
|
|
195
|
+Prop | Type | Optional | Default | Description
|
|
196
|
+---------------- | ------ | -------- | ---------------- | -----------
|
|
197
|
+style | style | Yes | | see [react-native documents][3]
|
|
198
|
+overlayStyle | style | Yes | | see [react-native documents][3]
|
|
199
|
+duration | number | Yes | 255 | determine the duration of loading-spinner-overlay animation
|
|
200
|
+delay | number | Yes | 0 | determine the delay of loading-spinner-overlay animation
|
|
201
|
+marginTop | number | Yes | 0 | determine the marginTop of the root container view, it is used when the modal prop is false
|
|
202
|
+modal | bool | Yes | true | determine if the modal will be used
|
|
203
|
+
|
|
204
|
+## Method
|
|
205
|
+
|
|
206
|
+* show({modal, marginTop, children, duration, easing, delay, animationEnd,})
|
|
207
|
+
|
|
208
|
+ * modal: determine if the modal will be used
|
|
209
|
+ * marginTop: determine the marginTop of the root container view, it is used when the modal prop is false
|
|
210
|
+ * children: determine the children of loading-spinner-overlay
|
|
211
|
+ * duration: determine the duration of animation
|
|
212
|
+ * easing: determine the easing of animation
|
|
213
|
+ * delay: determine the delay of animation
|
|
214
|
+ * animationEnd: determine the callback when animation is end
|
|
215
|
+
|
|
216
|
+* hide({duration, easing, delay, animationEnd,})
|
|
217
|
+
|
|
218
|
+ * duration: determine the duration of animation
|
|
219
|
+ * easing: determine the easing of animation
|
|
220
|
+ * delay: determine the delay of animation
|
|
221
|
+ * animationEnd: determine the callback when animation is end
|
|
222
|
+
|
|
223
|
+[0]: https://github.com/cyqresig/ReactNativeComponentDemos
|
|
224
|
+[1]: http://cyqresig.github.io/img/react-native-smart-loading-spinner-overlay-preview-ios-v1.0.0.gif
|
|
225
|
+[2]: http://cyqresig.github.io/img/react-native-smart-loading-spinner-overlay-preview-android-v1.0.0.gif
|
|
226
|
+[3]: https://facebook.github.io/react-native/docs/style.html
|
|
227
|
+[4]: http://facebook.github.io/react-native/docs/text.html#style
|