Skip to content

Commit 143852f

Browse files
Marco SciutoMarco Sciuto
authored andcommitted
Added ListView
1 parent e9e68cb commit 143852f

5 files changed

Lines changed: 61 additions & 46 deletions

File tree

App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ShoppingList from './src/components/ShoppingList';
55
import Header from './src/components/Header';
66

77

8-
export default class App extends Component {
8+
export default class App extends Component {
99
render() {
1010
return (
1111
<View style={styles.container}>

src/components/OrderItem.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const styles = StyleSheet.create({
4040
flex: 1,
4141
flexDirection: 'row',
4242
justifyContent: 'flex-start',
43-
borderWidth: 1,
4443
height: 200
4544
}
4645
});

src/components/ProductDetail.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ ProductDetail.propTypes = {
2222

2323
const styles = StyleSheet.create({
2424
wrapper: {
25-
borderWidth: 1,
26-
flex: 2
25+
flex: 1,
26+
justifyContent: 'center'
2727
},
2828
title: {
2929
fontSize: 16,

src/components/QuantityManager.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@ export default QuantityManager;
4141

4242
const styles = StyleSheet.create({
4343
wrapper: {
44-
borderWidth: 1,
4544
flex: 1,
46-
justifyContent: 'center'
45+
alignItems: 'center'
4746
},
4847
buttons: {
49-
flexDirection: 'row',
50-
borderWidth: 1,
48+
width: 50,
49+
flex: 1,
5150
justifyContent: 'center'
5251
}
5352
});

src/components/ShoppingList.js

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,75 @@
11
import React, { Component } from 'react';
2-
import { StyleSheet, ScrollView, View } from 'react-native';
2+
import { StyleSheet, View, ListView } from 'react-native';
33
import OrderItem from './OrderItem';
44
import Total from './Total';
55

66
class ShoppingList extends Component {
77
//state = { total: 0 };
88
constructor(props) {
99
super(props);
10-
/*this.ds = new ListView.DataSource({
10+
this.ds = new ListView.DataSource({
1111
rowHasChanged: (r1, r2) => r1.title !== r2.title
12-
});*/
13-
this.state = { total: 0 };
12+
});
13+
this.state = {
14+
total: 0,
15+
dataSource: this.ds.cloneWithRows([]),
16+
};
17+
}
18+
/*<OrderItem
19+
img="https://pbs.twimg.com/profile_images/569593540674473984/slHSRznT.jpeg"
20+
title="BUH"
21+
desc="buh"
22+
price={25.36}
23+
onQuantityUpdate={this.updateTotal.bind(this)}
24+
/>
25+
<OrderItem
26+
img="https://pbs.twimg.com/profile_images/569593540674473984/slHSRznT.jpeg"
27+
title="BUH"
28+
desc="buh"
29+
price={25.36}
30+
onQuantityUpdate={this.updateTotal.bind(this)}
31+
/>
32+
<OrderItem
33+
img="https://pbs.twimg.com/profile_images/569593540674473984/slHSRznT.jpeg"
34+
title="BUH"
35+
desc="buh"
36+
price={25.36}
37+
onQuantityUpdate={this.updateTotal.bind(this)}
38+
/>
39+
<OrderItem
40+
img="https://pbs.twimg.com/profile_images/569593540674473984/slHSRznT.jpeg"
41+
title="BUH"
42+
desc="buh"
43+
price={25.36}
44+
onQuantityUpdate={this.updateTotal.bind(this)}
45+
/>*/
46+
componentWillMount() {
47+
fetch('https://www.dmi.unict.it/~calanducci/LAP2/data.json',
48+
{ headers: { 'Cache-Control': 'no-cache' } }
49+
)
50+
.then(response => response.json())
51+
.then(responseData => this.setState({ dataSource: this.ds.cloneWithRows(responseData.items) }))
52+
.catch(error => alert('Errore caricando file json', error));
1453
}
15-
1654
updateTotal(amount) {
1755
this.setState({ total: this.state.total + amount });
1856
}
19-
2057
render() {
2158
return (
2259
<View style={styles.wrapper}>
2360
<Total total={this.state.total} />
24-
<ScrollView>
25-
26-
<OrderItem
27-
img="https://pbs.twimg.com/profile_images/569593540674473984/slHSRznT.jpeg"
28-
title="BUH"
29-
desc="buh"
30-
price={25.36}
31-
onQuantityUpdate={this.updateTotal.bind(this)}
32-
/>
33-
<OrderItem
34-
img="https://pbs.twimg.com/profile_images/569593540674473984/slHSRznT.jpeg"
35-
title="BUH"
36-
desc="buh"
37-
price={25.36}
38-
onQuantityUpdate={this.updateTotal.bind(this)}
39-
/>
40-
<OrderItem
41-
img="https://pbs.twimg.com/profile_images/569593540674473984/slHSRznT.jpeg"
42-
title="BUH"
43-
desc="buh"
44-
price={25.36}
45-
onQuantityUpdate={this.updateTotal.bind(this)}
46-
/>
47-
<OrderItem
48-
img="https://pbs.twimg.com/profile_images/569593540674473984/slHSRznT.jpeg"
49-
title="BUH"
50-
desc="buh"
51-
price={25.36}
52-
onQuantityUpdate={this.updateTotal.bind(this)}
53-
/>
54-
55-
</ScrollView>
61+
<ListView
62+
enableEmptySections
63+
dataSource={this.state.dataSource}
64+
renderRow={row =>
65+
<OrderItem
66+
img={row.thumbnailUrl}
67+
title={row.title}
68+
desc={row.description}
69+
price={row.price}
70+
onQuantityUpdate={this.updateTotal.bind(this)}
71+
/>}
72+
/>
5673
</View>
5774
);
5875
}

0 commit comments

Comments
 (0)