FixedHeaderList.js
3.62 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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import Immutable, {List, Record} from 'immutable';
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._renderHeader = this._renderHeader.bind(this);
this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => !Immutable.is(r1, r2)});
// this.dataSource = ds.cloneWithRows(this.props.content);
this.headers = [];
for (let i = 0; i < this.props.header.length; i++) {
this.headers.push(<Text style={styles.headerText}>{this.props.header[i]}</Text>);
if (i !== (this.props.header.length - 1)) {
this.headers.push(<View style={{width: 1, height: 14, backgroundColor: '#e5e5e5'}}/>);
}
}
}
_renderRow(rowData, sectionID, rowID) { // refactor later
return (
<TouchableHighlight onPress={() => {}} underlayColor={'white'} >
<View style={styles.row}>
<View style={styles.firstColumn}>
<Text style={styles.blackText}>{rowData.id}</Text>
<Text style={styles.blackText}>{rowData.date}</Text>
</View>
<Text style={styles.redText}>{rowData.num}</Text>
<Text style={styles.redText}>{rowData.amount}</Text>
</View>
</TouchableHighlight>
);
}
_renderHeader() {
return (
<View key={'listHeader'} style={styles.headerContainer}>
{this.headers}
</View>
);
}
render() {
return (
<ListView
style={styles.container}
dataSource={this.ds.cloneWithRows(this.props.content)}
renderRow={this._renderRow}
renderSeparator={(sectionID, rowID) => <View key={`${sectionID}-${rowID}`} style={styles.separator}/>}
renderHeader={this._renderHeader}
enableEmptySections={true}
/>
);
}
}
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',
}
});