-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.js
70 lines (65 loc) · 1.91 KB
/
Home.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
import { StyleSheet, Text, View, ScrollView } from 'react-native';
import { SearchBar } from 'react-native-elements';
import { useEffect, useState } from 'react';
import LocationCard from './LocationCard';
import { locations } from './data';
export default function Home({ navigation }) {
const [search, setSearch] = useState("");
const [searchResults, setSearchResults] = useState(locations);
useEffect(() => {
setSearchResults(locations.filter((element) => element.name.toLowerCase().indexOf(search.toLowerCase()) != -1));
}, [search]);
return (
<View style={styles.container}>
<Text style={styles.titleText}>
Explore
</Text>
<View style={styles.mainContent}>
<SearchBar
styles={styles.searchBar}
showLoading={false}
platform={Platform.OS}
clearIcon={true}
onChangeText={(text) => setSearch(text)}
placeholder='Discover Places'
cancelButtonTitle='Cancel'
value={search}
/>
<ScrollView>
<View style={{paddingBottom: 100}}>
{searchResults.map((element, index) => (
<LocationCard city={element.name}
distance={element.distance}
image={element.image}
onPress={() => {navigation.navigate('Location', {"information": element})}} />
))}
</View>
</ScrollView>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
paddingTop: 125,
marginLeft: 0,
},
baseText: {
fontFamily: 'Cochin',
},
titleText: {
fontSize: 60,
fontWeight: 'bold',
marginLeft: 25,
},
searchBar: {
maxWidth: 100
},
mainContent: {
alignItems: 'center',
justifyContent: 'center',
paddingHorizontal: 25,
}
});