FixedHeaderList.js
5.89 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import Immutable, {List, Record} from 'immutable';
import PlainTextSection from './PlainTextSection';
import Placeholder from './Placeholder';
import LoadMoreIndicator from './indicator/LoadMoreIndicator';
import DatePicker from './DatePicker';
import moment from 'moment';
const {
Component,
} = React;
const {
View,
Text,
Image,
ListView,
TouchableHighlight,
Dimensions,
StyleSheet,
} = ReactNative;
export default class FixedHeaderList extends Component {
// static propTypes = {
// content: React.PropTypes.arrayOf(
// React.PropTypes.shape({
// type: React.PropTypes.string,
// thumb: React.PropTypes.number,
// title: React.PropTypes.string,
// })
// ),
// onPress: React.PropTypes.func,
// };
constructor(props) {
super(props);
this._renderRow = this._renderRow.bind(this);
// this.dataSource = ds.cloneWithRows(this.props.content);
this.ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
});
}
_renderRow(rowData, sectionID, rowID) {
switch (sectionID) {
case 'SECTION_HEADER':
return (
<View style={styles.container}>
<PlainTextSection content={rowData.section2} />
<Placeholder containerStyle={{borderBottomWidth: 0}}/>
</View>
);
case 'SECTION_TIME':
return (
<View style={styles.container}>
<DatePicker currentStartDate={this.props.currentStartDate}
currentEndDate={this.props.currentEndDate}
maxDate={this.props.maxDate}
newDatePicked={this.props.newDatePicked}
showDatePickerIOS={this.props.showDatePickerIOS}/>
<Placeholder containerStyle={{borderBottomWidth: 0}}/>
</View>
);
case 'SECTION_TITLE':
let headers = [];
for (let i = 0; i < rowData.header.length; i++) {
headers.push(<Text style={styles.headerText}>{rowData.header[i]}</Text>);
if (i !== (rowData.header.length - 1)) {
headers.push(<View style={{width: 1, height: 14, backgroundColor: '#e5e5e5'}}/>);
}
}
return (
<View key={'listHeader'} style={styles.headerContainer}>
{headers}
</View>
);
case 'SECTION_CONTENT':
return (
<TouchableHighlight onPress={() => {}} underlayColor={'white'} >
<View style={styles.row}>
<View style={styles.firstColumn}>
<Text style={styles.blackText}>{rowData.requisitionFormId || rowData.outFormId}</Text>
<Text style={styles.blackText}>{moment(rowData.dateId, 'YYYYMMDD').format('YYYY-MM-DD')}</Text>
</View>
<Text style={styles.redText}>{rowData.inStorageNums || rowData.outStorageNums}</Text>
<Text style={styles.redText}>{(rowData.inStorageAmount && rowData.inStorageAmount.toFixed(2)) || (rowData.outStorageAmount && rowData.outStorageAmount.toFixed(2))}</Text>
</View>
</TouchableHighlight>
);
default:
return (
<Text>Error data source</Text>
);
}
}
render() {
let isFetching = this.props.isFetching;
let loadText = '暂无更多数据';
if (!this.props.reachEnd) {
loadText = isFetching ? '正在加载...' : '上拉加载更多';
}
return (
<ListView
style={styles.container}
dataSource={this.ds.cloneWithRowsAndSections(this.props.section.toJS())}
renderRow={this._renderRow}
renderSeparator={(sectionID, rowID) => <View key={`${sectionID}-${rowID}`} style={styles.separator}/>}
onEndReached={this.props.requestData}
enableEmptySections={true}
removeClippedSubviews={false}
renderFooter={()=>{
return <LoadMoreIndicator
hidden={this.props.hideLoadingFooter}
loadingText={loadText}
animating={isFetching}
/>
}}
/>
);
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
container: {
flex: 1,
},
separator: {
height: 1,
},
headerContainer: {
flexDirection: 'row',
backgroundColor: 'white',
height: 45,
alignItems: 'center',
borderBottomColor: '#F0F0F0',
borderBottomWidth: 1,
},
headerText: {
fontSize: 14,
color: '#444444',
textAlign: 'center',
flex: 1,
},
row: {
flexDirection: 'row',
paddingTop: 15,
paddingBottom: 15,
alignItems: 'center',
backgroundColor: 'white',
},
firstColumn: {
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
},
blackText: {
fontSize: 14,
color: '#444444',
textAlign: 'center',
},
redText: {
fontSize: 14,
color: '#D0021B',
flex: 1,
textAlign: 'center',
}
});