Skip to content

Commit 7de5632

Browse files
lh_wanglh_wang
authored andcommitted
add list component
1 parent f1ae95f commit 7de5632

File tree

7 files changed

+267
-225
lines changed

7 files changed

+267
-225
lines changed

nearby/Nearby/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ var Nearby = React.createClass({
4343
style={styles.container}
4444
initialRoute={{
4545
component: Food,
46-
title: '美食'
46+
title: '美食',
47+
rightButtonTitle:'地图',
4748
}}
4849
/>
4950
</TabBarIOS.Item>
@@ -60,7 +61,8 @@ var Nearby = React.createClass({
6061
tintColor="#fff"
6162
initialRoute={{
6263
component: Film,
63-
title: '电影'
64+
title: '电影',
65+
rightButtonTitle:'地图',
6466
}}
6567
/>
6668
</TabBarIOS.Item>
@@ -77,24 +79,27 @@ var Nearby = React.createClass({
7779
tintColor="#fff"
7880
initialRoute={{
7981
component: Bank,
80-
title: '银行'
82+
title: '银行',
83+
rightButtonTitle:'地图',
8184
}}
8285
/>
8386
</TabBarIOS.Item>
8487

8588
<TabBarIOS.Item
86-
title='厕所'
87-
selected={this.state.selected === '厕所'}
89+
title='卫生间'
90+
selected={this.state.selected === '卫生间'}
8891
icon={require("image!toilet")}
89-
onPress={()=>{this.setState({selected: '厕所'})}}>
92+
onPress={()=>{this.setState({selected: '卫生间'})}}>
9093
<NavigatorIOS
9194
style={styles.container}
9295
barTintColor='#007AFF'
9396
titleTextColor="#fff"
9497
tintColor="#fff"
9598
initialRoute={{
9699
component: Toilet,
97-
title: '厕所'
100+
title: '卫生间',
101+
rightButtonTitle:'地图',
102+
onRightButtonPress: function(){alert(0)}
98103
}}
99104
/>
100105
</TabBarIOS.Item>

nearby/Nearby/views/bank.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
var React = require('react-native');
2-
3-
var {
4-
View
5-
} = React;
61

2+
var React = require('react-native');
3+
var List = require('./list');
74
var Bank = React.createClass({
85
render: function(){
9-
return (
10-
<View></View>
6+
return(
7+
<List type="银行" nav={this.props.navigator}/>
118
);
129
}
1310
});
1411

1512
module.exports = Bank;
16-
File renamed without changes.

nearby/Nearby/views/film.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
var React = require('react-native');
2-
3-
var {
4-
View
5-
} = React;
61

2+
var React = require('react-native');
3+
var List = require('./list');
74
var Film = React.createClass({
85
render: function(){
9-
return (
10-
<View></View>
6+
return(
7+
<List type="电影院" nav={this.props.navigator}/>
118
);
129
}
1310
});
1411

1512
module.exports = Film;
16-

nearby/Nearby/views/food.js

Lines changed: 4 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -1,203 +1,12 @@
1-
var React = require('react-native');
2-
var Util = require('./util');
3-
var FoodDetail = require('./foodDetail');
4-
5-
var {
6-
View,
7-
ScrollView,
8-
Text,
9-
StyleSheet,
10-
TextInput,
11-
ActivityIndicatorIOS,
12-
TouchableOpacity
13-
} = React;
141

2+
var React = require('react-native');
3+
var List = require('./list');
154
var Food = React.createClass({
16-
getInitialState: function() {
17-
return {
18-
list: null,
19-
count: 0,
20-
keywords: ''
21-
};
22-
},
235
render: function(){
24-
var items = [];
25-
if(this.state.list){
26-
var len = this.state.list.length > 10 ? 10 : this.state.list.length;
27-
for(var i = 0; i < len; i++){
28-
var obj = this.state.list[i];
29-
items.push(
30-
<TouchableOpacity style={styles.item} onPress={this._loadDetail.bind(this, obj.id, obj.name)}>
31-
<View style={styles.row}>
32-
<View style={{flex:1}}>
33-
<Text numberOfLines={1} style={styles.name}>{obj.name}</Text>
34-
<Text numberOfLines={1} style={styles.type}>{obj.type}</Text>
35-
</View>
36-
<View style={styles.distance}>
37-
<Text numberOfLines={1} style={styles.mi}>{obj.distance}</Text>
38-
<Text numberOfLines={1} style={styles.address}>{obj.address}</Text>
39-
</View>
40-
</View>
41-
42-
<TouchableOpacity style={styles.phone}>
43-
<Text numberOfLines={1} >电话</Text>
44-
</TouchableOpacity>
45-
</TouchableOpacity>
46-
);
47-
}
48-
}
49-
return (
50-
<ScrollView style={styles.container}>
51-
<View style={styles.searchBg}>
52-
<TextInput style={styles.input} placeholder="搜索美食"
53-
onChangeText={this._onChangeText}
54-
onEndEditing={this._onEndEditing}/>
55-
<View>
56-
<Text style={styles.tip}>
57-
已为您筛选
58-
<Text style={{color:'#FA2530'}}>{this.state.count}</Text>
59-
条数据
60-
</Text>
61-
</View>
62-
</View>
63-
{items}
64-
{items.length? null : <View style={styles.activity}><ActivityIndicatorIOS color="#248BFD"/></View>}
65-
<View style={{height:40}}></View>
66-
</ScrollView>
6+
return(
7+
<List type="餐饮" nav={this.props.navigator}/>
678
);
68-
},
69-
componentDidMount: function(){
70-
var url = Util.searchURL + 'key=' + Util.amapKey + '&keywords=美食&location=121.390686,31.213976&extensions=base';
71-
var that = this;
72-
Util.getJSON(url, function(data){
73-
if(data.status && data.info === 'OK'){
74-
var count = data.pois.length > 10? 10: data.pois.length;
75-
that.setState({
76-
list: data.pois,
77-
count: count
78-
});
79-
}else{
80-
alert('没有查询到相应的数据');
81-
}
82-
});
83-
},
84-
85-
/*加载详情页*/
86-
_loadDetail: function(id, name){
87-
this.props.navigator.push({
88-
component: FoodDetail,
89-
title: name,
90-
passProps:{
91-
id: id
92-
}
93-
});
94-
},
95-
96-
_onChangeText: function(val){
97-
this.setState({
98-
keywords: val
99-
});
100-
},
101-
_onEndEditing: function(){
102-
var that = this;
103-
var keywords = this.state.keywords;
104-
var url = Util.searchURL + 'key=' + Util.amapKey + '&keywords='
105-
+ keywords + '&types=餐饮&location=121.390686,31.213976&extensions=base';
106-
that.setState({
107-
list: null
108-
});
109-
Util.getJSON(url, function(data){
110-
if(data.status && data.info === 'OK' && data.pois.length){
111-
var count = data.pois.length > 10? 10: data.pois.length;
112-
that.setState({
113-
list: data.pois,
114-
count: count
115-
});
116-
}else{
117-
alert('没有查询到相应的数据');
118-
}
119-
});
1209
}
121-
12210
});
123-
124-
var styles = StyleSheet.create({
125-
container:{
126-
flex:1,
127-
backgroundColor:'#ddd'
128-
},
129-
input:{
130-
height:38,
131-
marginLeft:10,
132-
marginRight:10,
133-
borderWidth:Util.pixel,
134-
paddingLeft:5,
135-
marginTop:10,
136-
borderColor: '#868687',
137-
borderRadius:3,
138-
fontSize:15
139-
},
140-
tip:{
141-
fontSize:12,
142-
marginLeft:10,
143-
marginTop:5,
144-
color: '#505050'
145-
},
146-
row:{
147-
flexDirection:'row',
148-
marginLeft:10,
149-
marginRight:10,
150-
marginTop:10,
151-
paddingTop:5
152-
},
153-
distance:{
154-
width:120,
155-
alignItems:'flex-end',
156-
},
157-
name:{
158-
fontSize:15,
159-
marginBottom:6
160-
},
161-
type:{
162-
fontSize:12,
163-
color:'#686868'
164-
},
165-
mi:{
166-
fontSize:12,
167-
color:'#686868'
168-
},
169-
address:{
170-
fontSize:14,
171-
color:'#686868'
172-
},
173-
phone:{
174-
marginLeft:10,
175-
marginRight:10,
176-
height:33,
177-
marginTop:10,
178-
justifyContent:'center',
179-
alignItems:'center',
180-
borderWidth:Util.pixel,
181-
borderColor:'#ccc'
182-
},
183-
searchBg:{
184-
backgroundColor:'#fff',
185-
paddingBottom:10
186-
},
187-
item:{
188-
marginTop:10,
189-
backgroundColor:'#fff',
190-
paddingBottom:10,
191-
borderTopWidth:Util.pixel,
192-
borderBottomWidth:Util.pixel,
193-
borderColor:'#ccc'
194-
},
195-
activity:{
196-
marginTop:50,
197-
justifyContent:'center',
198-
alignItems:'center',
199-
}
200-
});
201-
20211
module.exports = Food;
20312

0 commit comments

Comments
 (0)