-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.js
90 lines (85 loc) · 1.82 KB
/
search.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
import React, { useState } from "react";
import {
TouchableOpacity,
StyleSheet,
ScrollView,
View,
Text,
TextInput,
} from "react-native";
import SearchBar from "./SearchBar/SearchBar"
export default function Search() {
const [data] = useState([
["Superstore"],
"puma",
"McDonalds",
"Walmart",
"shopping",
"grocery",
"fitness",
"health",
"01/15/2022",
"yoyo",
]);
const [filtered, setFiltered] = useState(data);
const [searching, setSearching] = useState(false);
const onSearch = (text) => {
if (text) {
setSearching(true);
const temp = text.toLowerCase();
const tempList = data.filter((item) => {
if (item.match(temp)) return item;
});
setFiltered(tempList);
} else {
setSearching(false);
setFiltered(data);
}
};
return (
<View style={styles.container}>
<TextInput
style={styles.textInput}
placeholder="Search"
placeholderTextColor="white"
onChangeText={onSearch}
/>
<View
style={{
justifyContent: "center",
alignContent: "center",
alignItems: "center",
}}
>
<View
style={{
flexWrap: "wrap",
flexDirection: "row",
justifyContent: "center",
}}
></View>
</View>
{searching && (
<SearchBar onPress={() => setSearching(false)} dataSource={filtered} />
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
// justifyContent: 'center',
alignItems: "center",
marginTop: "20%",
flex: 1,
backgroundColor: "#A9A9A9",
},
textInput: {
backgroundColor: "#A9A9A9",
width: "80%",
borderRadius: 5,
height: 50,
fontSize: 20,
fontWeight: "bold",
paddingHorizontal: 10,
},
});