SideMenu.js
3.31 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
'use strict';
import React from "react-native";
import Button from "apsl-react-native-button";
import {Actions} from "react-native-router-flux";
import Immutable, {List} from 'immutable';
let {
Component,
View,
Text,
ListView,
StyleSheet,
TouchableHighlight,
Dimensions
} = React;
export default class SideMenu extends React.Component {
static propTypes = {
items: React.PropTypes.instanceOf(List),
onPressItem: React.PropTypes.func,
};
constructor(props) {
super(props);
this._renderHeader = this._renderHeader.bind(this);
this._renderSeparator = this._renderSeparator.bind(this);
this._renderRow = this._renderRow.bind(this);
this._pressRow = this._pressRow.bind(this);
this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => !Immutable.is(r1, r2)});
}
_pressRow(rowID) {
this.props.onPressItem && this.props.onPressItem(rowID);
}
_renderHeader(sectionData, sectionID) {
return (
<Text style={styles.header}>
店铺切换
</Text>
);
}
_renderSeparator(sectionID, rowID, adjacentRowHighlighted) {
return (
<View style={styles.separator} key={rowID}/>
);
}
_renderRow(rowData, sectionID, rowID) {
return (
<TouchableHighlight onPress={() => this._pressRow(rowID)} underlayColor={'white'} key={rowID}>
<View style={styles.row} >
<Text style={styles.text}>
{rowData.name}
</Text>
</View>
</TouchableHighlight>
);
}
render(){
return (
<View style={[styles.container]}>
<View style={styles.statusBar} />
<View style={styles.listContainer}>
<ListView
contentContainerStyle={styles.contentContainer}
dataSource={this.ds.cloneWithRows(this.props.items.toArray())}
renderHeader={this._renderHeader}
renderSeparator={this._renderSeparator}
renderRow={this._renderRow}
enableEmptySections={true}
/>
</View>
</View>
);
}
}
SideMenu.contextTypes = {
drawer: React.PropTypes.object
};
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#F0F0F0",
},
statusBar: {
backgroundColor: '#3E3E3E',
paddingTop: 0,
top: 0,
height: 20,
right: 0,
left: 0,
position: 'absolute',
},
listContainer: {
top: 20,
height: height - 20,
},
contentContainer: {
backgroundColor: 'white',
},
header: {
fontSize: 18,
color: '#B0B0B0',
top: 10,
right: 15,
height: 28,
alignSelf: 'flex-end',
},
separator: {
height: 1,
backgroundColor: '#E0E0E0',
},
row: {
height: 65,
justifyContent: 'center',
backgroundColor: 'transparent',
},
text: {
fontSize: 18,
color: '#444444',
fontWeight: 'bold',
left: 14,
},
});