forked from mattfrances/CryptoPriceTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
112 lines (102 loc) · 2.79 KB
/
App.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
import React, {useRef, useMemo, useState, useEffect} from 'react';
import { FlatList, StyleSheet, Text, View, SafeAreaView } from 'react-native';
import ListItem from './components/ListItem';
import Chart from './components/Chart';
import {
BottomSheetModal,
BottomSheetModalProvider,
} from '@gorhom/bottom-sheet';
import { getMarketData } from './services/cryptoService';
const ListHeader = () => (
<>
<View style={styles.titleWrapper}>
<Text style={styles.largeTitle}>Markets</Text>
</View>
<View style={styles.divider} />
</>
)
export default function App() {
const [data, setData] = useState([]);
const [selectedCoinData, setSelectedCoinData] = useState(null);
useEffect(() => {
const fetchMarketData = async () => {
const marketData = await getMarketData();
setData(marketData);
}
fetchMarketData();
}, [])
const bottomSheetModalRef = useRef(null);
const snapPoints = useMemo(() => ['50%'], []);
const openModal = (item) => {
setSelectedCoinData(item);
bottomSheetModalRef.current?.present();
}
return (
<BottomSheetModalProvider>
<SafeAreaView style={styles.container}>
<FlatList
keyExtractor={(item) => item.id}
data={data}
renderItem={({ item }) => (
<ListItem
name={item.name}
symbol={item.symbol}
currentPrice={item.current_price}
priceChangePercentage7d={item.price_change_percentage_7d_in_currency}
logoUrl={item.image}
onPress={() => openModal(item)}
/>
)}
ListHeaderComponent={<ListHeader />}
/>
</SafeAreaView>
<BottomSheetModal
ref={bottomSheetModalRef}
index={0}
snapPoints={snapPoints}
style={styles.bottomSheet}
>
{ selectedCoinData ? (
<Chart
currentPrice={selectedCoinData.current_price}
logoUrl={selectedCoinData.image}
name={selectedCoinData.name}
symbol={selectedCoinData.symbol}
priceChangePercentage7d={selectedCoinData.price_change_percentage_7d_in_currency}
sparkline={selectedCoinData?.sparkline_in_7d.price}
/>
) : null}
</BottomSheetModal>
</BottomSheetModalProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
titleWrapper: {
marginTop: 20,
paddingHorizontal: 16,
},
largeTitle: {
fontSize: 24,
fontWeight: "bold",
},
divider: {
height: StyleSheet.hairlineWidth,
backgroundColor: '#A9ABB1',
marginHorizontal: 16,
marginTop: 16,
},
bottomSheet: {
shadowColor: "#000",
shadowOffset: {
width: 0,
height: -4,
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5,
},
});