-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
137 lines (127 loc) · 3.35 KB
/
App.js
File metadata and controls
137 lines (127 loc) · 3.35 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* eslint-disable semi */
/* eslint-disable react-native/no-inline-styles */
/* eslint-disable prettier/prettier */
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, { useState, useRef, useEffect, useMemo, useCallback } from 'react';
import {
ActivityIndicator,
FlatList,
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
} from 'react-native';
import {
BottomSheetModal,
BottomSheetModalProvider,
} from '@gorhom/bottom-sheet';
// custom
import Chart from "./app/components/Chart";
import List from "./app/components/List";
import { getMarketData } from "./app/services/geckoApi";
export default function App() {
// bottom sheet
const bottomSheetModalRef = useRef(null);
const [selectedCoin, setSelectedCoinFunc] = useState(null);
// variables
const snapPoints = useMemo(() => ['45%'], []);
// callbacks
const handlePresentModalPress = useCallback(item => {
// console.log(item);
bottomSheetModalRef.current?.present();
setSelectedCoinFunc(item);
}, []);
// data
const [data, setData] = useState([]);
useEffect(() => {
const fetchMarketData = async () => {
const marketData = await getMarketData();
setData(marketData);
};
fetchMarketData();
}, []);
const ListHeader = () => {
return (
<>
<View style={styles.headerView}>
<Text style={styles.boldTitle}>Market</Text>
</View>
<View style={styles.devider} />
</>
)
}
return (
<BottomSheetModalProvider>
<SafeAreaView style={{ flex: 1 }}>
<StatusBar hidden={false} backgroundColor="#767676" />
<View style={styles.container}>
{data ? (
<FlatList
data={data}
ListHeaderComponent={<ListHeader />}
keyExtractor={(item) => item.id}
renderItem={({ item }) => (
<List
name={item.name}
symbol={item.symbol}
currentPrice={item.current_price}
price7D={item.price_change_percentage_7d_in_currency}
logo={item.image}
onPress={() => handlePresentModalPress(item)}
/>
)}
/>) : (
<ActivityIndicator />
)}
</View>
</SafeAreaView>
<BottomSheetModal
ref={bottomSheetModalRef}
index={0}
snapPoints={snapPoints}
>
<View style={styles.contentContainer}>
{selectedCoin ? <Chart
name={selectedCoin.name}
symbol={selectedCoin.symbol}
currentPrice={selectedCoin.current_price}
price7D={selectedCoin.price_change_percentage_7d_in_currency}
logo={selectedCoin.image}
sparkline={selectedCoin?.sparkline_in_7d.price}
/> : null}
</View>
</BottomSheetModal>
</BottomSheetModalProvider>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
},
headerView: {
margin: 2,
paddingHorizontal: 16,
},
devider: {
marginHorizontal: 16,
backgroundColor: '#A9ABB1',
height: StyleSheet.hairlineWidth,
marginTop: 16,
},
boldTitle: {
fontSize: 24,
fontWeight: "700",
color: "#A9ABB1",
marginTop: 10,
}
});