-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
107 lines (98 loc) · 2.83 KB
/
App.tsx
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
import 'react-native-gesture-handler'
import {useCallback, useEffect, useMemo, useRef, useState} from "react";
import {FlatList, Platform, StyleSheet, Text, View} from 'react-native';
import {BottomSheetModal, BottomSheetModalProvider} from '@gorhom/bottom-sheet';
import {ListItem} from "./components/ListItem";
import {Chart} from "./components/Chart";
import {getMarketData} from "./services/cryptoService";
if (Platform.OS === 'android') {
require('intl');
require('intl/locale-data/jsonp/en-US');
}
export default function App() {
const [data, setData] = useState<any>([])
const [selectedCoinData, setSelectedCoinData] = useState<any>(null)
console.log(data[0])
useEffect(() => {
(async function() {
const marketData = await getMarketData()
setData(marketData)
})()
}, [])
const bottomSheetModalRef = useRef<BottomSheetModal>(null);
const snapPoints = useMemo(() => ['45%'], []);
const openModal = useCallback((item) => {
setSelectedCoinData(item)
bottomSheetModalRef.current?.present();
}, []);
return (
<BottomSheetModalProvider>
<View style={styles.container}>
<Text style={styles.mainTitle}>Markets</Text>
<View style={styles.divider}/>
<FlatList
data={data}
renderItem={({item}) => (
<ListItem
name={item.name}
symbol={item.symbol}
currentPrice={item.current_price}
priceChange={item.price_change_percentage_24h}
image={item.image}
openModal={() => openModal(item)}/>
)}
keyExtractor={item => item.id}
/>
<BottomSheetModal
ref={bottomSheetModalRef}
index={0}
snapPoints={snapPoints}
style={styles.bottomSheet}
>
{selectedCoinData &&
<Chart
name={selectedCoinData.name}
symbol={selectedCoinData.symbol}
currentPrice={selectedCoinData.current_price}
priceChange={selectedCoinData.price_change_percentage_24h}
image={selectedCoinData.image}
sparkline={selectedCoinData.sparkline_in_7d.price}
/>
}
</BottomSheetModal>
</View>
</BottomSheetModalProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
paddingHorizontal: 16,
},
mainTitle: {
fontSize: 24,
fontWeight: "700",
marginTop: 40,
},
divider: {
height: 0.5,
backgroundColor: '#A9ABB1',
marginTop: 16,
},
contentContainer: {
flex: 1,
alignItems: 'center',
},
bottomSheet: {
shadowColor: '#000',
shadowOffset: {
width: 0,
height: -4,
},
shadowOpacity: 0.2,
shadowRadius: 4,
elevation: 5,
backgroundColor: '#fff',
},
});