-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlistScreen.js
More file actions
57 lines (49 loc) · 1.93 KB
/
listScreen.js
File metadata and controls
57 lines (49 loc) · 1.93 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
import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { FlatList, Text, View, Button, TouchableHighlight, TouchableOpacity, Image } from 'react-native';
import { removeItem } from './ItemsActions';
import { styles } from './styles'
import { data } from './data';
function ListScreen(props) {
const ItemView = ({ item, index }) => {
return (
<View style={styles.listItem}>
<View style={{ flex: 1 }}>
<Image
source={ data[data.findIndex(element => element.groceryItem.localeCompare(item.groceryItem) == 0)].src }
style={styles.itemImage}
/>
</View>
<Text style={styles.itemTextStyle} onPress={() => props.removeItem(index)}>{item.groceryItem}</Text>
</View>
);
};
const ItemSeparatorView = () => {
return (
<View style={styles.fList} />
);
};
return (
<View style={styles.container2}>
<Text style={styles.heading11}>JIV'S GROCERIES</Text>
<Text style={styles.heading2}>Groceries</Text>
<Text>You have {props.items.current.length} items in your list.</Text>
<FlatList
data={props.items.current}
ItemSeparatorComponent={ItemSeparatorView}
renderItem={ItemView}
keyExtractor={item => item.id} />
<TouchableOpacity
onPress={() => props.navigation.navigate('Add Items')}>
<Text style={styles.myListText}>Click Here to Add Items to Your List!</Text>
</TouchableOpacity>
</View>
);
}
const mapStateToProps = (state) => {
const { items } = state
return { items }
};
const mapDispatchToProps = dispatch => (bindActionCreators({ removeItem }, dispatch));
export default connect(mapStateToProps, mapDispatchToProps)(ListScreen);