-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeScreen.js
More file actions
224 lines (189 loc) · 5.59 KB
/
HomeScreen.js
File metadata and controls
224 lines (189 loc) · 5.59 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import React, { Component, useState, useEffect } from 'react';
import {StyleSheet, Text, View, SafeAreaView, Image,ScrollView, Button, useWindowDimensions, Alert, ImageBackground} from 'react-native';
import {colors} from "./src/constants";
import Keyboard from "./src/components/Keyboard";
import { useNavigation} from '@react-navigation/native'
import { Auth, Storage } from "aws-amplify";
import SearchableDropdown from 'react-native-searchable-dropdown';
import { TextInput } from 'react-native-gesture-handler';
import image2 from './assets/images/forestbackground.jpeg'
import Logo from './assets/images/house2.png'
import { DataStore } from '@aws-amplify/datastore';
import { SchoolArray } from './src/models';
const HomeScreen = () => {
const [items, setItems] = useState([])
const update_Array = async(newname) => {
await DataStore.save(
new SchoolArray({
name: newname
})
);
//items.push({name: newname})
get_data()
}
const get_data = async() => {
const items1 = [
{ name: 'Irvington' },
];
console.log("Geting Data")
const posts = await DataStore.query(SchoolArray);
var arrayLength = posts.length;
for (var i = 0; i < arrayLength; i++) {
items1.push({name: posts[i].name})
}
setItems(items1)
}
const navigation = useNavigation()
const {fontScale} = useWindowDimensions();
const styles = makeStyles(fontScale);
const [newschoolname, setnewschoolname] = useState('');
const {height} = useWindowDimensions();
useEffect(() => {
get_data()
}, []);
const signOut = () => {
Auth.signOut()
}
return (
// items.push({
// name: newschoolname})
//<SafeAreaView style={styles.container}>
// <ImageBackground source={image2} resizeMode="cover" style={styles.image}>
<View style={styles.container}>
<Text style={styles.titleText}>
Find your School
</Text>
<Image source ={Logo}
style = {[styles.logo, {height: height * 0.15}]}
resizeMode = "contain" >
</Image>
<SearchableDropdown
onTextChange={(text) => console.log(text)}
//On text change listner on the searchable input
onItemSelect={(item) => navigation.navigate('SchoolHomePage', {
schoolname: JSON.stringify(item)
})
}
//onItemSelect called after the selection from the dropdown
containerStyle={{ padding: 5 }}
//suggestion container style
textInputStyle={{
//inserted text style
marginTop: '5%',
padding: 12,
borderWidth: 1,
borderColor: '#ccc',
backgroundColor: '#FAF7F6',
borderRadius: 10
}}
itemStyle={{
//single dropdown item style
padding: 10,
marginTop: 2,
backgroundColor: '#FAF9F8',
borderColor: '#bbb',
borderWidth: 1,
}}
itemTextStyle={{
//text style of a single dropdown item
color: '#222',
}}
itemsContainerStyle={{
//items container style you can pass maxHeight
//to restrict the items dropdown hieght
maxHeight: '60%',
}}
items={items}
//mapping of item array
defaultIndex={2}
//default selected item index
placeholder="Name of School (City)"
//place holder for the search input
resetValue={false}
//reset textInput Value with true and false state
underlineColorAndroid="transparent"
//To remove the underline from the android input
/>
<Text style={styles.headingText} > Don't see your school?
Add it to the list </Text>
<TextInput
style = {{
top: '10%',
fontSize: 12,
marginTop: '5%',
padding: 12,
borderWidth: 1,
borderColor: '#ccc',
backgroundColor: '#FAF7F6',
borderRadius: 10
}}
placeholder = "Name of School (City)"
onChangeText={newText => setnewschoolname(newText)
}
>
</TextInput>
< View style = {{top: '15%'}}>
<Text style = {{
width: '100%',
textAlign: 'center',
color: 'blue',
fontSize: 25/fontScale
}}
onPress = {() =>
{
update_Array(newschoolname)
Alert.alert(newschoolname, "was added successfully")
}
}>
Add
</Text>
</View>
<Text
onPress={signOut}
style = {{
width: '100%',
textAlign: 'center',
color: 'red',
marginTop: 'auto',
marginVertical: 20,
fontSize: 20
}}>
Sign Out
</Text>
</View>
// </ImageBackground>
// </SafeAreaView>
);
};
export default HomeScreen;
const makeStyles = fontScale => StyleSheet.create({
image: {
flex: 1,
justifyContent: "center"
},
container: {
flex: 1,
backgroundColor: '#ADD8E6',
padding: 10,
},
titleText: {
padding: 8,
fontSize: 25/fontScale,
textAlign: 'center',
fontWeight: 'bold',
},
headingText: {
fontSize: 25/fontScale,
top: '5%',
textAlign: 'center',
},
logo:{
alignContent: 'center',
justifyContent: 'center',
alignSelf: 'center',
marginBottom: 20,
width: '70%',
maxWidth: 300,
maxHeight: 200
}
});