-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDemo.js
142 lines (131 loc) · 3.79 KB
/
Demo.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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component, PropTypes } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
FlatList,
VirtualizedList,
Dimensions,
Animated,
PanResponder,
Easing,
ScrollView,
TouchableOpacity
} from 'react-native';
import Util from './util'
import RefreshFlatList, { RefreshState, ViewType } from './RefreshFlatList'
const {height, width} = Dimensions.get('window');
export default class Demo extends Component {
constructor() {
super()
this.state = {
headerHeight: 100,
refreshing: false,
_data: [],
footerMsg: 'loading'
}
}
componentDidMount() {
let a = Util.makeDataImmttable()
let c = a.toJS()
this.setState({_data: Util.makeData()})
}
_onRefreshFun = () => {
console.log('refresh request')
this.setState({refreshing: true})
setTimeout(() => {
console.log('refresh down')
this.setState({refreshing: false})
},2000)
}
_onEndReached = () => {
this.setState({footerMsg: 'loading'})
this.timer2 = setTimeout(() => {
let _d = this.state._data.concat(Util.makeData(this.state._data.length))
this.setState({footerMsg: 'load more', _data: _d})
}, 1000)
}
_onLoadFun = () => {
}
_renderItem = () => {
// ListView
return (
<View style={{width: width, height: 100}} >
<Text>{'ListView + ' + item.title} </Text>
</View>
)
// ScrollView
/*return (
<View style={{width: width, height: 100}} >
<Text>{'ScrollView' + item.text} </Text>
</View>
)*/
}
_customerHeader = (refreshState, percent) => {
const { headerHeight, msg } = this.state
switch (refreshState) {
case RefreshState.pullToRefresh:
return (
<Animated.View style={{justifyContent: 'center', alignItems: 'center', width: width, height: headerHeight, backgroundColor: 'red'}} >
<Text>{ 'pull to refresh' + percent }</Text>
</Animated.View>
)
case RefreshState.releaseToRefresh:
return (
<Animated.View style={{justifyContent: 'center', alignItems: 'center', width: width, height: headerHeight, backgroundColor: 'red'}} >
<Text>{ 'release to refresh' + percent }</Text>
</Animated.View>
)
case RefreshState.refreshing:
return (
<Animated.View style={{justifyContent: 'center', alignItems: 'center', width: width, height: headerHeight, backgroundColor: 'red'}} >
<Text>{ 'refreshing...' + percent }</Text>
</Animated.View>
)
case RefreshState.refreshdown:
return (
<Animated.View style={{justifyContent: 'center', alignItems: 'center', width: width, height: headerHeight, backgroundColor: 'red'}} >
<Text>{ 'refresh down' }</Text>
</Animated.View>
)
default:
}
}
_listFooterComponent = () => {
return (
<View style={{ flex:1, justifyContent: 'center', alignItems: 'center',width: width, height: 30, backgroundColor: 'red'}} >
<Text style={{textAlign: 'center',}}> { this.state.footerMsg } </Text>
</View>
)
}
render() {
return (
<View style={styles.container}>
<RefreshFlatList
data={this.state._data}
refreshing={this.state.refreshing}
onEndReached={this._onEndReached}
customRefreshView={this._customerHeader}
ListFooterComponent={this._listFooterComponent}
renderItem={this._renderItem}
onRefreshFun={this._onRefreshFun}
viewType={ViewType.ListView}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
}
});