Skip to content

Commit e84363b

Browse files
committed
fix: Replace ~ banner with news carousel in topmenu.
1 parent 16b2f01 commit e84363b

File tree

2 files changed

+79
-32
lines changed

2 files changed

+79
-32
lines changed
Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,75 @@
1-
import React from "react";
2-
import { Image } from "react-native";
1+
import React, { useEffect, useRef } from "react";
2+
import { Image, TouchableOpacity, View } from "react-native";
33

44
import { TopMenuSection } from "./TopMenuSection";
5-
import { useBanners } from "../../hooks/marketing/useBanners";
65
import { useSelectedNetworkId } from "../../hooks/useSelectedNetwork";
7-
import { web3ToWeb2URI } from "../../utils/ipfs";
8-
import FlexCol from "../FlexCol";
9-
import { Link } from "../Link";
10-
import { PrimaryBox } from "../boxes/PrimaryBox";
6+
import { useNews } from "@/hooks/marketing/useNews";
7+
import { News } from "@/api/marketplace/v1/marketplace";
8+
import Carousel, { ICarouselInstance } from "react-native-reanimated-carousel";
9+
import { FullWidthSeparator } from "../FullWidthSeparator";
10+
import { Section } from "../Section";
11+
import { NewsBox } from "../hub/NewsBox";
12+
import { SVG } from "../SVG";
1113

12-
export const TopMenuHighlightedNews: React.FC = () => {
14+
import chevronLeftSVG from "../../../assets/icons/chevron-left.svg";
15+
import chevronRightSVG from "../../../assets/icons/chevron-right.svg";
16+
import { fontSemibold10, fontSemibold14 } from "@/utils/style/fonts";
17+
18+
export const SmallNewsCarouselSection: React.FC = () => {
19+
const width = 298
20+
const carouselRef = useRef<ICarouselInstance | null>(null);
21+
const renderItem = (props: { item: News }) =>
22+
<NewsBox news={props.item} imageHeight={210} imageWidth={210}
23+
titleTextStyle={fontSemibold14} subtitleTextStyle={fontSemibold10} boxWidth={298} />;
1324
const networkId = useSelectedNetworkId();
14-
const banners = useBanners(networkId);
15-
const banner = banners?.length ? banners[0] : undefined;
25+
const news = useNews(networkId);
26+
27+
const topRightChild = (
28+
<View style={{ flexDirection: "row", alignItems: "center" }}>
29+
<TouchableOpacity
30+
onPress={() => carouselRef.current?.prev()}
31+
style={{ marginRight: 24 }}
32+
>
33+
<SVG width={16} height={16} source={chevronLeftSVG} />
34+
</TouchableOpacity>
35+
36+
<TouchableOpacity onPress={() => carouselRef.current?.next()}>
37+
<SVG width={16} height={16} source={chevronRightSVG} />
38+
</TouchableOpacity>
39+
</View>
40+
);
41+
42+
useEffect(() => {
43+
carouselRef.current?.next();
44+
}, [width]);
45+
46+
return (
47+
<Section topRightChild={topRightChild}>
48+
{/*TODO: Async fetchMore for these data ?*/}
49+
50+
<Carousel
51+
width={width}
52+
data={news || []}
53+
ref={carouselRef}
54+
onConfigurePanGesture={(g) => g.enableTrackpadTwoFingerGesture(true)}
55+
height={650}
56+
pagingEnabled
57+
loop
58+
autoPlay
59+
autoPlayInterval={3000}
60+
renderItem={renderItem}
61+
/>
62+
<FullWidthSeparator />
63+
</Section>
64+
);
65+
};
1666

67+
68+
export const TopMenuHighlightedNews: React.FC = () => {
69+
const networkId = useSelectedNetworkId();
1770
return (
1871
<TopMenuSection title="Highlighted News">
19-
<FlexCol>
20-
<Link to={banner?.url || ""}>
21-
<PrimaryBox>
22-
<Image
23-
source={{
24-
uri: web3ToWeb2URI(banner?.image),
25-
}}
26-
style={{
27-
height: 94,
28-
width: 298,
29-
borderRadius: 7,
30-
}}
31-
/>
32-
</PrimaryBox>
33-
</Link>
34-
</FlexCol>
72+
<SmallNewsCarouselSection/>
3573
</TopMenuSection>
3674
);
3775
};

packages/components/hub/NewsBox.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useLinkTo } from "@react-navigation/native";
22
import React, { useCallback } from "react";
3-
import { Image, Linking, useWindowDimensions, View } from "react-native";
3+
import { Image, Linking, TextStyle, useWindowDimensions, View } from "react-native";
44

55
import { News } from "../../api/marketplace/v1/marketplace";
66
import { web3ToWeb2URI } from "../../utils/ipfs";
@@ -19,8 +19,16 @@ const breakPoint = 768;
1919

2020
export const NewsBox: React.FC<{
2121
news: News;
22-
}> = ({ news }) => {
23-
const { width } = useWindowDimensions();
22+
imageHeight?:number
23+
imageWidth?:number
24+
titleTextStyle?:TextStyle
25+
subtitleTextStyle?:TextStyle
26+
boxWidth?:number
27+
}> = ({ news,imageHeight,imageWidth,titleTextStyle,boxWidth}) => {
28+
let { width } = useWindowDimensions();
29+
if(boxWidth){
30+
width=boxWidth
31+
}
2432
const linkTo = useLinkTo();
2533
const navigateTo = useCallback(
2634
(to: string | undefined) => {
@@ -44,6 +52,7 @@ export const NewsBox: React.FC<{
4452
borderBottomColor: neutral33,
4553
paddingHorizontal: 10,
4654
paddingVertical: 20,
55+
display:"flex"
4756
}}
4857
>
4958
<View
@@ -64,7 +73,7 @@ export const NewsBox: React.FC<{
6473
]}
6574
>
6675
<View>
67-
<GradientText gradientType="blueExtended" style={fontSemibold28}>
76+
<GradientText gradientType="blueExtended" style={titleTextStyle || fontSemibold28}>
6877
{news.title}
6978
</GradientText>
7079
<BrandText style={fontSemibold20}>{news.subtitle}</BrandText>
@@ -114,8 +123,8 @@ export const NewsBox: React.FC<{
114123
<Image
115124
source={{ uri: web3ToWeb2URI(news.image) }}
116125
style={{
117-
height: 342,
118-
width: 342,
126+
height: imageHeight || 342,
127+
width: imageWidth || 342,
119128
aspectRatio: 1,
120129
borderRadius: 10,
121130
}}

0 commit comments

Comments
 (0)