@@ -25,7 +25,6 @@ const PaginationStatus = {
25
25
waiting : 1 ,
26
26
allLoaded : 2
27
27
} ;
28
- const headerHeight = 80 ;
29
28
30
29
export default class RefreshableScrollView extends ScrollView {
31
30
_offsetY = 0 ;
@@ -36,19 +35,14 @@ export default class RefreshableScrollView extends ScrollView {
36
35
super ( props ) ;
37
36
this . state = {
38
37
arrowAngle : new Animated . Value ( 0 ) ,
39
- refreshStatus : RefreshStatus . pullToRefresh ,
40
- refreshTitle : this . props . refreshableTitlePull ,
41
- date : this . props . date
38
+ refreshStatus : RefreshStatus . refreshing ,
39
+ refreshTitle : this . props . refreshableTitleRefreshing ,
40
+ date : this . props . date ,
41
+ showRefreshHeader : false
42
42
} ;
43
43
}
44
44
45
- endRefresh ( ) {
46
- this . onRefreshEnd ( ) ;
47
- }
48
-
49
45
componentDidMount ( ) {
50
- const height = this . props . customRefreshView ? this . props . customRefreshViewHeight : headerHeight ;
51
- setTimeout ( ( ) => this . refs . scrollView . scrollTo ( { x : 0 , y : height , animated : true } ) , 1 ) ;
52
46
AsyncStorage . getItem ( DATE_KEY , ( error , result ) => {
53
47
if ( result ) {
54
48
result = parseInt ( result ) ;
@@ -66,14 +60,14 @@ export default class RefreshableScrollView extends ScrollView {
66
60
onScroll = ( event ) => {
67
61
//console.log('onScroll()');
68
62
const y = event . nativeEvent . contentOffset . y ;
69
- const height = this . props . customRefreshView ? this . props . customRefreshViewHeight : headerHeight ;
63
+ const height = this . props . refreshViewHeight ;
70
64
if ( y <= height ) {
71
65
this . _offsetY = y - height ;
72
66
}
73
67
if ( this . _dragFlag ) {
74
68
if ( ! this . _isRefreshing ) {
75
69
if ( y <= 10 ) {
76
- if ( this . state . refresStatus !== RefreshStatus . releaseToRefresh ) {
70
+ if ( this . state . refreshStatus !== RefreshStatus . releaseToRefresh ) {
77
71
this . setState ( {
78
72
refreshStatus : RefreshStatus . releaseToRefresh ,
79
73
refreshTitle : this . props . refreshableTitleRelease
@@ -85,7 +79,7 @@ export default class RefreshableScrollView extends ScrollView {
85
79
} ) . start ( ) ;
86
80
}
87
81
} else {
88
- if ( this . state . refresStatus !== RefreshStatus . pullToRefresh ) {
82
+ if ( this . state . refreshStatus !== RefreshStatus . pullToRefresh ) {
89
83
this . setState ( {
90
84
refreshStatus : RefreshStatus . pullToRefresh ,
91
85
refreshTitle : this . props . refreshableTitlePull
@@ -112,7 +106,7 @@ export default class RefreshableScrollView extends ScrollView {
112
106
onScrollBeginDrag = ( event ) => {
113
107
//console.log('onScrollBeginDrag()');
114
108
this . _dragFlag = true ;
115
- const height = this . props . customRefreshView ? this . props . customRefreshViewHeight : headerHeight ;
109
+ const height = this . props . refreshViewHeight ;
116
110
this . _offsetY = event . nativeEvent . contentOffset . y - height ;
117
111
if ( this . props . onScrollBeginDrag ) {
118
112
this . props . onScrollBeginDrag ( event )
@@ -122,7 +116,7 @@ export default class RefreshableScrollView extends ScrollView {
122
116
onScrollEndDrag = ( event ) => {
123
117
this . _dragFlag = false ;
124
118
const y = event . nativeEvent . contentOffset . y ;
125
- const height = this . props . customRefreshView ? this . props . customRefreshViewHeight : headerHeight ;
119
+ const height = this . props . refreshViewHeight ;
126
120
this . _offsetY = y - height ;
127
121
//console.log('onScrollEndDrag()' + y);
128
122
if ( ! this . _isRefreshing ) {
@@ -163,52 +157,61 @@ export default class RefreshableScrollView extends ScrollView {
163
157
this . _isRefreshing = false ;
164
158
const now = new Date ( ) . getTime ( ) ;
165
159
this . setState ( {
166
- refreshStatus : RefreshStatus . pullToRefresh ,
167
- refreshTitle : this . props . refreshableTitlePull ,
168
- date : dateFormat ( now , this . props . dateFormat )
160
+ showRefreshHeader : true ,
169
161
} ) ;
162
+ setTimeout ( ( ) => {
163
+ this . refs . scrollView . scrollTo ( { x : 0 , y : this . props . refreshViewHeight , animated : true } ) ;
164
+ this . setState ( {
165
+ refreshStatus : RefreshStatus . pullToRefresh ,
166
+ refreshTitle : this . props . refreshableTitlePull ,
167
+ date : dateFormat ( now , this . props . dateFormat )
168
+ } ) ;
169
+ } , 1000 ) ;
170
+
170
171
AsyncStorage . setItem ( DATE_KEY , now . toString ( ) ) ;
171
172
Animated . timing ( this . state . arrowAngle , {
172
173
toValue : 0 ,
173
174
duration : 50 ,
174
175
easing : Easing . inOut ( Easing . quad )
175
176
} ) . start ( ) ;
176
- const height = this . props . customRefreshView ? this . props . customRefreshViewHeight : headerHeight ;
177
- this . refs . scrollView . scrollTo ( { x : 0 , y : height , animated : true } ) ;
178
177
}
179
178
} ;
180
179
181
180
renderRefreshHeader ( ) {
182
181
if ( this . props . customRefreshView ) {
183
182
return (
184
- this . props . customRefreshView ( this . state . refresStatus , this . _offsetY )
183
+ < View style = { [ defaultHeaderStyles . header , this . props . refreshViewStyle ] } >
184
+ { this . props . customRefreshView ( this . state . refreshStatus , this . _offsetY ) }
185
+ </ View >
185
186
) ;
186
187
}
187
188
188
189
return (
189
- < View style = { defaultHeaderStyles . background } >
190
+ < View style = { [ defaultHeaderStyles . header , this . props . refreshViewStyle , { height : this . state . showRefreshHeader ? this . props . refreshViewHeight : 0 } ] } >
190
191
< View style = { defaultHeaderStyles . status } >
191
192
{ this . renderSpinner ( ) }
192
193
< Text style = { defaultHeaderStyles . statusTitle } > { this . state . refreshTitle } </ Text >
193
194
</ View >
194
195
{ this . props . displayDate &&
195
- < Text style = { defaultHeaderStyles . date } > { this . props . dateTitle + this . state . date } </ Text >
196
+ < Text
197
+ style = { [ defaultHeaderStyles . date , this . props . dateStyle ] } > { this . props . dateTitle + this . state . date } </ Text >
196
198
}
197
199
</ View >
198
200
) ;
199
201
}
200
202
201
203
renderSpinner ( ) {
202
- if ( this . state . refreshStatus == RefreshStatus . refreshing ) {
204
+ if ( this . state . refreshStatus === RefreshStatus . refreshing ) {
203
205
return (
204
206
< ActivityIndicator style = { { marginRight : 10 } } />
205
207
)
206
208
}
207
209
return (
208
210
< Animated . Image
209
- source = { { uri : this . props . arrowImage } }
211
+ source = { this . props . arrowImageSource }
210
212
resizeMode = { 'contain' }
211
213
style = { [ defaultHeaderStyles . arrow ,
214
+ this . props . arrowImageStyle ,
212
215
{
213
216
transform : [ {
214
217
rotateX : this . state . arrowAngle . interpolate ( {
@@ -228,6 +231,7 @@ export default class RefreshableScrollView extends ScrollView {
228
231
{ ...this . props }
229
232
scrollEventThrottle = { 16 }
230
233
onScroll = { this . onScroll }
234
+ //contentContainerStyle={{paddingBottom: 80}}
231
235
//onMomentumScrollEnd={this.onScrollEndDrag}
232
236
onScrollEndDrag = { this . onScrollEndDrag }
233
237
onScrollBeginDrag = { this . onScrollBeginDrag } >
@@ -239,14 +243,13 @@ export default class RefreshableScrollView extends ScrollView {
239
243
}
240
244
241
245
const defaultHeaderStyles = StyleSheet . create ( {
242
- background : {
246
+ header : {
243
247
width : width ,
248
+ height : 80 ,
244
249
alignItems : 'center' ,
245
- height : headerHeight ,
246
- justifyContent : 'center' ,
250
+ justifyContent : 'center'
247
251
} ,
248
252
status : {
249
- height : 27 ,
250
253
flexDirection : 'row' ,
251
254
alignItems : 'center'
252
255
} ,
0 commit comments