-
Notifications
You must be signed in to change notification settings - Fork 22
/
NewsCarouselSection.tsx
63 lines (55 loc) · 2.09 KB
/
NewsCarouselSection.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
import React, { useEffect, useRef } from "react";
import { View, TouchableOpacity } from "react-native";
import Carousel, { ICarouselInstance } from "react-native-reanimated-carousel";
import chevronLeftSVG from "../../../assets/icons/chevron-left.svg";
import chevronRightSVG from "../../../assets/icons/chevron-right.svg";
import { News } from "../../api/marketplace/v1/marketplace";
import { useMaxResolution } from "../../hooks/useMaxResolution";
import { useSelectedNetworkId } from "../../hooks/useSelectedNetwork";
import { FullWidthSeparator } from "../FullWidthSeparator";
import { SVG } from "../SVG";
import { Section } from "../Section";
import { NewsBox } from "../hub/NewsBox";
import { useNews } from "@/hooks/marketing/useNews";
export const NewsCarouselSection: React.FC = () => {
const { width } = useMaxResolution();
const carouselRef = useRef<ICarouselInstance | null>(null);
const renderItem = (props: { item: News }) => <NewsBox news={props.item} />;
const networkId = useSelectedNetworkId();
const news = useNews(networkId);
const topRightChild = (
<View style={{ flexDirection: "row", alignItems: "center" }}>
<TouchableOpacity
onPress={() => carouselRef.current?.prev()}
style={{ marginRight: 24 }}
>
<SVG width={16} height={16} source={chevronLeftSVG} />
</TouchableOpacity>
<TouchableOpacity onPress={() => carouselRef.current?.next()}>
<SVG width={16} height={16} source={chevronRightSVG} />
</TouchableOpacity>
</View>
);
useEffect(() => {
carouselRef.current?.next();
}, [width]);
return (
<Section title="Highlighted News" topRightChild={topRightChild}>
<FullWidthSeparator />
{/*TODO: Async fetchMore for these data ?*/}
<Carousel
width={width}
data={news || []}
ref={carouselRef}
onConfigurePanGesture={(g) => g.enableTrackpadTwoFingerGesture(true)}
height={382}
pagingEnabled
loop
autoPlay
autoPlayInterval={3000}
renderItem={renderItem}
/>
<FullWidthSeparator />
</Section>
);
};