-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bikes.tsx
75 lines (64 loc) · 2.15 KB
/
Bikes.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
import React, { FC, useRef, useCallback, useState } from 'react';
import { FlashList } from '@shopify/flash-list';
import { SafeAreaView } from 'react-native-safe-area-context';
import { ActivityIndicator, Platform, View } from 'react-native';
import { useRoute } from '@react-navigation/native';
import { BottomSheetModal as GorhomBottomSheetModal } from '@gorhom/bottom-sheet';
import { useBikes } from '@app/hooks';
import {
BikeCard,
BottomSheetModal,
NavBarHeader,
BikeDetailsModal,
} from '@app/components';
import { Bike } from '@app/models';
import styles from './styles';
const snapPoints = Platform.OS === 'ios' ? ['88%'] : ['92%'];
const Bikes: FC = () => {
const { data, isLoading, refetch } = useBikes();
const [selectedBike, setSelectedBike] = useState<Bike | null>(null);
const bottomSheetRef = useRef<GorhomBottomSheetModal>(null);
const route = useRoute();
const handleBikeCardOnPress = useCallback((item: Bike) => {
setSelectedBike(item);
bottomSheetRef.current?.present();
}, []);
const itemSeparatorComponent = useCallback(
() => <View style={styles.listItemSeparator} />,
[]
);
const handleCloseModal = useCallback(
() => bottomSheetRef.current?.dismiss(),
[]
);
return (
<SafeAreaView edges={['bottom']} style={styles.container}>
<NavBarHeader title={route.name} />
<View style={styles.listContainer}>
{data && (
<FlashList
renderItem={({ item }: { item: Bike }) => (
<BikeCard
onPress={() => handleBikeCardOnPress(item)}
data={item}
/>
)}
estimatedItemSize={200}
data={data}
ItemSeparatorComponent={itemSeparatorComponent}
refreshing={isLoading}
onRefresh={refetch}
/>
)}
{isLoading && <ActivityIndicator color="white" size="large" />}
</View>
<BottomSheetModal ref={bottomSheetRef} snapPoints={snapPoints}>
<BikeDetailsModal
handleCloseModal={handleCloseModal}
data={selectedBike}
/>
</BottomSheetModal>
</SafeAreaView>
);
};
export default Bikes;