-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
96 lines (87 loc) · 2.11 KB
/
App.js
File metadata and controls
96 lines (87 loc) · 2.11 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
import React, { useEffect, useState } from "react";
import {
StyleSheet,
Text,
View,
FlatList,
TextInput,
StatusBar,
} from "react-native";
import CoinItem from "./components/CoinItem";
const App = () => {
const [coins, setCoins] = useState([]);
const [search, setSearch] = useState("");
const [refresing, setRefresing] = useState(false)
const loadData = async () => {
const res = await fetch(
"https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=100&page=1&sparkline=false"
);
const data = await res.json();
setCoins(data);
};
useEffect(() => {
console.log("Cargué");
loadData();
}, []);
return (
<View style={styles.container}>
<StatusBar backgroundColor='#141414' />
<View style={styles.header}>
<Text style={styles.title}>Coin Tracker by A2R</Text>
<TextInput
style={styles.searchInput}
onChangeText={text => setSearch(text)}
placeholder='Search a coin'
placeholderTextColor='#858585'
/>
</View>
<FlatList
style={styles.list}
data={coins.filter(
(coin) =>
coin.name.toLowerCase().includes(search) ||
coin.symbol.toLowerCase().includes(search)
)}
renderItem={({ item }) => {
return <CoinItem coin={item} />;
}}
showsVerticalScrollIndicator={false}
refreshing={refresing}
onRefresh={async () => {
console.log('Refreshing')
await loadData();
setRefresing(false)
}}
/>
</View>
);
};
export default App;
const styles = StyleSheet.create({
container: {
backgroundColor: "#141414",
alignItems: "center",
flex: 1,
},
title: {
color: "#fff",
marginTop: 10,
fontSize: 20,
},
list: {
width: "90%",
},
header: {
flexDirection: "row",
justifyContent: "space-between",
width: "90%",
marginBottom: 10,
},
searchInput: {
color: "#fff",
borderBottomColor: "#4657CE",
borderBottomWidth: 1,
width: "40%",
textAlign: "center",
},
});