4
4
StyleSheet,
5
5
View,
6
6
Platform,
7
+ PullToRefreshViewAndroid,
7
8
} = React
8
9
var ListView = require ( './ListView' )
9
10
var createElementFrom = require ( './createElementFrom' )
10
11
var RefreshingIndicator = require ( './RefreshingIndicator' )
12
+ var scrollToCompat = require ( './scrollToCompat' )
11
13
12
14
const SCROLL_EVENT_THROTTLE = 32
13
15
const MIN_PULLDOWN_DISTANCE = 40
@@ -27,6 +29,8 @@ const LISTVIEW_REF = 'listview'
27
29
28
30
var ControlledRefreshableListView = React . createClass ( {
29
31
propTypes : {
32
+ colors : PropTypes . array ,
33
+ progressBackgroundColor : PropTypes . string ,
30
34
onRefresh : PropTypes . func . isRequired ,
31
35
isRefreshing : PropTypes . bool . isRequired ,
32
36
waitingForRelease : PropTypes . bool ,
@@ -63,6 +67,8 @@ var ControlledRefreshableListView = React.createClass({
63
67
scrollEventThrottle : SCROLL_EVENT_THROTTLE ,
64
68
ignoreInertialScroll : true ,
65
69
refreshingIndicatorComponent : RefreshingIndicator ,
70
+ pullingPrompt : 'Pull to refresh' ,
71
+ holdingPrompt : 'Release to refresh' ,
66
72
}
67
73
} ,
68
74
getInitialState ( ) {
@@ -81,9 +87,11 @@ var ControlledRefreshableListView = React.createClass({
81
87
if (
82
88
this . isReleaseUpdate ( this . props , this . state , nextProps , nextState )
83
89
) {
84
- this . getScrollResponder ( ) . scrollWithoutAnimationTo (
90
+ scrollToCompat (
91
+ this . getScrollResponder ( ) ,
85
92
- ( this . lastContentInsetTop + REFRESHING_INDICATOR_HEIGHT ) ,
86
- this . lastContentOffsetX
93
+ this . lastContentOffsetX ,
94
+ false
87
95
)
88
96
}
89
97
}
@@ -93,13 +101,18 @@ var ControlledRefreshableListView = React.createClass({
93
101
if (
94
102
this . isReleaseUpdate ( prevProps , prevState , this . props , this . state )
95
103
) {
96
- this . getScrollResponder ( ) . scrollWithoutAnimationTo (
104
+ scrollToCompat (
105
+ this . getScrollResponder ( ) ,
97
106
- ( this . lastContentInsetTop ) ,
98
- this . lastContentOffsetX
107
+ this . lastContentOffsetX ,
108
+ false
99
109
)
100
110
}
101
111
}
102
112
} ,
113
+ handlePullToRefreshViewAndroidRef ( swipeRefreshLayout ) {
114
+ this . swipeRefreshLayout = swipeRefreshLayout
115
+ } ,
103
116
handleScroll ( e ) {
104
117
var scrollY = e . nativeEvent . contentInset . top + e . nativeEvent . contentOffset . y
105
118
this . lastScrollY = scrollY
@@ -184,39 +197,56 @@ var ControlledRefreshableListView = React.createClass({
184
197
pullingIndicator,
185
198
holdingIndicator,
186
199
refreshingIndicator,
187
- pullingPrompt : pullingPrompt || 'Pull to refresh' ,
188
- holdingPrompt : holdingPrompt || 'Release to refresh' ,
200
+ pullingPrompt : pullingPrompt ,
201
+ holdingPrompt : holdingPrompt ,
189
202
refreshingPrompt : refreshingPrompt || refreshDescription ,
190
203
isTouching : this . isTouching ,
191
204
isWaitingForRelease : this . isWaitingForRelease ( ) ,
192
205
}
193
206
return createElementFrom ( this . props . refreshingIndicatorComponent , refreshingIndicatorProps )
194
207
} ,
195
208
render ( ) {
196
- return (
197
- < View style = { [ stylesheet . container ] } >
198
- < View style = { [ stylesheet . fillParent ] } >
199
- { this . renderRefreshingIndicator ( ) }
200
- </ View >
201
- < View style = { [ stylesheet . fillParent ] } >
209
+ if ( Platform . OS === 'android' ) {
210
+ return (
211
+ < PullToRefreshViewAndroid
212
+ ref = { this . handlePullToRefreshViewAndroidRef }
213
+ onRefresh = { this . props . onRefresh }
214
+ colors = { this . props . colors }
215
+ progressBackgroundColor = { this . props . progressBackgroundColor }
216
+ style = { stylesheet . container }
217
+ >
202
218
< ListView
203
219
{ ...this . props }
204
220
ref = { LISTVIEW_REF }
205
- contentContainerStyle = { this . getContentContainerStyle ( ) }
206
- onScroll = { this . handleScroll }
207
- scrollEventThrottle = { this . props . scrollEventThrottle }
208
- onResponderGrant = { this . handleResponderGrant }
209
- onResponderRelease = { this . handleResponderRelease }
210
221
/>
222
+ </ PullToRefreshViewAndroid >
223
+ )
224
+ } else {
225
+ return (
226
+ < View style = { [ stylesheet . container ] } >
227
+ < View style = { [ stylesheet . fillParent ] } >
228
+ { this . renderRefreshingIndicator ( ) }
229
+ </ View >
230
+ < View style = { [ stylesheet . fillParent ] } >
231
+ < ListView
232
+ { ...this . props }
233
+ ref = { LISTVIEW_REF }
234
+ contentContainerStyle = { this . getContentContainerStyle ( ) }
235
+ onScroll = { this . handleScroll }
236
+ scrollEventThrottle = { this . props . scrollEventThrottle }
237
+ onResponderGrant = { this . handleResponderGrant }
238
+ onResponderRelease = { this . handleResponderRelease }
239
+ />
240
+ </ View >
211
241
</ View >
212
- </ View >
213
- )
242
+ )
243
+ }
214
244
} ,
215
245
} )
216
246
217
247
var stylesheet = StyleSheet . create ( {
218
248
container : {
219
- // flex: 1,
249
+ flex : 1 ,
220
250
} ,
221
251
fillParent : {
222
252
backgroundColor : 'transparent' ,
@@ -226,22 +256,6 @@ var stylesheet = StyleSheet.create({
226
256
right : 0 ,
227
257
bottom : 0 ,
228
258
} ,
229
- // offsetParent: {
230
- // position: 'relative',
231
- // },
232
- // positionTopLeft: {
233
- // position: 'absolute',
234
- // top: 0,
235
- // left: 0,
236
- // },
237
- // fill: {
238
- // flex: 1
239
- // },
240
- // center: {
241
- // flex: 1,
242
- // justifyContent: 'space-around',
243
- // alignItems: 'center',
244
- // },
245
259
} )
246
260
247
261
module . exports = ControlledRefreshableListView
0 commit comments