-
Notifications
You must be signed in to change notification settings - Fork 10
/
MenuList.js
191 lines (164 loc) · 4.48 KB
/
MenuList.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
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
189
190
191
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
ListView,
Image,
PixelRatio,
TouchableHighlight,
TouchableOpacity,
Alert,
BackAndroid,
} from 'react-native';
const MENU=['我的消息','积分商城','会员中心','在线听歌免流量','听歌识曲','主题换肤','夜间模式','定时停止播放','音乐闹钟','驾驶模式'];
export default class MenuList extends Component{
constructor(){
super();
var ds=new ListView.DataSource({rowHasChanged:(r1,r2)=>r1!==r2});
this.state={
dataSource:ds.cloneWithRows(MENU),
}
}
renderHeader(){
return(
//切记:height:null width:null 要设置,否则height width会图片原有的宽度
<Image resizeMode='cover' style={styles.headImg}
source={require('./images/topinfo_ban_bg.jpg')}>
<View style={[styles.headOpacity]}/>
<View style={[styles.headImg,{justifyContent:'center',alignItems:'center'}]}>
<View style={styles.headText}>
<Text style={{color:'#e3e3e2'}}>登陆网易云音乐</Text>
<Text style={{color:'#e3e3e2',marginTop:5}}>320K高音质无限下载,手机电脑多端同步</Text>
</View>
<TouchableOpacity activeOpacity={0.5} style={{marginTop:20}} onPress={()=>console.log()}>
<View style={styles.login}>
<Text style={{color:'#fff'}}>立即登录</Text>
</View>
</TouchableOpacity>
</View>
</Image>
);
}
renderRow(data,sectionID,rowID){
var image;
switch (rowID) {
case '0':
image=require('image!opmenu_icn_msg');
break;
case '1':
image=require('image!topmenu_icn_store');
break;
case '2':
image=require('image!topmenu_icn_member');
break;
case '3':
image=require('image!topmenu_icn_free');
break;
case '4':
image=require('image!topmenu_icn_identify');
break;
case '5':
image=require('image!topmenu_icn_skin');
break;
case '6':
image=require('image!topmenu_icn_night');
break;
case '7':
image=require('image!topmenu_icn_time');
break;
case '8':
image=require('image!topmenu_icn_clock');
break;
case '9':
image=require('image!topmenu_icn_vehicle');
break;
default:
}
return(
<View style={{flex:1}}>
<TouchableHighlight underlayColor='#ddd' onPress={()=>this.onSelectItem(rowID)}>
<View style={styles.item} >
<Image style={{width:40,height:40}} source={image}/>
<Text style={{color:'#333333',marginLeft:5,fontSize:16}}>{data}</Text>
</View>
</TouchableHighlight>
{rowID==3?<View style={{backgroundColor:'#d8dadb', height:1/PixelRatio.get()}}/>:null}
</View>
);
}
/**
每项点击
**/
onSelectItem(position){
var func=this.props.onMenuItem;
func&&func(position);
}
render(){
return (
<View style={{flex:1}}>
<ListView
style={{backgroundColor:'#ebedee'}}
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)}
renderHeader={this.renderHeader.bind(this)}
/>
<View style={{flexDirection:'row',height:46,alignItems:'center'}}>
<TouchableHighlight style={{flex:1}} underlayColor='#ddd' onPress={()=>alert('设置')}>
<View style={styles.btn}><Text>设置</Text></View>
</TouchableHighlight>
<View style={{backgroundColor:'#d8dadb', width:1/PixelRatio.get(),height:20,}}/>
<TouchableHighlight style={{flex:1}} underlayColor='#ddd'
onPress={()=>{
Alert.alert('退出应用','确定要退出吗?',
[
{text:'确定',onPress:()=>{BackAndroid.exitApp()}},
{text:'取消',onPress:()=>{}}
]
);
}
}>
<View style={styles.btn}><Text>退出应用</Text></View>
</TouchableHighlight>
</View>
</View>
);
}
}
const styles=StyleSheet.create({
headImg:{
height:160,
width:300,
},
headOpacity:{
height:160,
width:300,
backgroundColor:'#000',
opacity:0.2,
position:'absolute',
},
headText:{
alignItems:'center',
justifyContent:'center',
},
login:{
borderWidth:1,
borderColor:'#fff',
borderRadius:3,
height:33,
width:142,
alignItems:'center',
justifyContent:'center',
},
item:{
height:50,
flexDirection:'row',
alignItems:'center',
paddingLeft:10,
},
btn:{
flex:1,
alignItems:'center',
justifyContent:'center',
}
});