This repository has been archived by the owner on Dec 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeScreen.js
147 lines (132 loc) · 3.41 KB
/
HomeScreen.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
import React, {Component} from 'react';
import {
Text,
TextInput,
View,
StyleSheet,
Button,
ScrollView,
FlatList,
TouchableHighlight
} from 'react-native';
let SQLite = require('react-native-sqlite-storage');
class HomeScreen extends Component {
static navigationOptions ={
title: 'Mall Directory',
};
constructor(props){
super(props)
this.state ={
categories: [],
keyword: "",
};
this._query = this._query.bind(this);
this.db = SQLite.openDatabase({
name: 'db',
createFromLocation: '~db.sqlite'
}, this.openDb, this.errorDb);
}
componentDidMount() {
this._query();
}
_query() {
this.db.transaction((tx) => {
tx.executeSql('SELECT * FROM categories', [], (tx,results) => {
this.setState({
categories: results.rows.raw(),
})
})
});
}
openDb(){
console.log('Database opened');
}
errorDb(err){
console.log("SQL error: " + err);
}
render () {
return (
<ScrollView>
<View style={styles.container}>
<TextInput
style={styles.input}
placeholder={'Enter Shop Name Here...'}
onChangeText= {(keyword)=> {
this.setState({keyword})
}}
>
</TextInput>
<TouchableHighlight
underlayColor={'#cccccc'}
onPress={() => this.props.navigation.navigate("Search", {
keyword: this.state.keyword,
})}
><Text style={styles.search}>Search</Text>
</TouchableHighlight>
</View>
<View>
<Text style={styles.sectionHeader}>Categories</Text>
</View>
<View>
<FlatList
data={this.state.categories}
showsVerticalScrollIndicator = {true}
renderItem = {({item})=>
<TouchableHighlight
underlayColor={'#cccccc'}
onPress={() => {
this.props.navigation.navigate('CategoryShopList', {
category: item.category,
})
}}
>
<View style={styles.item}>
<Text style={styles.itemTitle}>{item.category}</Text>
</View>
</TouchableHighlight>
}
keyExtractor={(item) => {item.id.toString()}}
/>
</View>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
padding: 10,
flexDirection: 'row'
}, search: {
flex: 1,
fontSize: 20,
textAlignVertical: 'center',
color: 'white',
backgroundColor: 'green',
borderColor: '#ccc',
padding: 10,
marginLeft: 10,
}, input: {
flex: 3,
fontSize: 20,
}, item: {
justifyContent: 'center',
paddingTop: 10,
paddingBottom: 10,
paddingLeft: 25,
paddingRight: 25,
borderBottomWidth: 1,
borderColor: '#ccc',
}, itemTitle: {
fontSize: 22,
fontWeight: '500',
color: '#000',
}, itemSubtitle: {
fontSize: 18,
}, sectionHeader :{
fontSize: 25,
marginLeft: 10
},
});
export default HomeScreen;