Skip to content

Commit

Permalink
fix(llm): fix carousel pagination for content cards
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasWerey committed Mar 27, 2024
1 parent 7c5fd0c commit 9cd49aa
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-moose-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

fix pagination for carousel
3 changes: 2 additions & 1 deletion apps/ledger-live-mobile/src/contentCards/cards/types.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ComponentProps } from "react";
import { TouchableOpacity } from "react-native-gesture-handler";
import { AnyContentCard } from "../../dynamicContent/types";

export type ButtonAction = ComponentProps<typeof TouchableOpacity>["onPress"];

export type ContentCardProps = {
export type ContentCardProps = AnyContentCard & {
metadata: ContentCardMetadata;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Carousel = ContentLayoutBuilder<Props>(({ items, styles: _styles = default

const separatorWidth = useTheme().space[styles.gap];

const isPaginationEnabled = styles.pagination && styles.widthFactor >= WidthFactor.ThreeQuarters;
const isPaginationEnabled = styles.pagination;

const carouselRef = useRef<FlatList>(null);
const [carouselIndex, setCarouselIndex] = useState(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,33 @@ import React from "react";
import { ContentCardItem, ContentCardProps } from "~/contentCards/cards/types";
import Bullet from "~/contentCards/layouts/carousel/pagination/bullets";
import { getItemStatus } from "~/contentCards/layouts/carousel/pagination/utils";
import { WidthFactor } from "../../types";

type Props<P extends ContentCardProps> = {
items: ContentCardItem<P>[];
carouselIndex: number;
};

const Pagination = <P extends ContentCardProps>({ items, carouselIndex }: Props<P>) => (
<Flex
alignSelf="center"
flexDirection="row"
columnGap={4}
justifyContent="center"
width={250}
overflow="hidden"
>
{items.map((item, index) => (
<Bullet key={item.props.metadata.id} type={getItemStatus(index, carouselIndex)} />
))}
</Flex>
);
const Pagination = <P extends ContentCardProps>({ items, carouselIndex }: Props<P>) => {
const hasHalfWidth = items[0].props.carouselWidthFactor === WidthFactor.Half;
const isSmallCard = carouselIndex === items.length - 2 && hasHalfWidth;
return (
<Flex
alignSelf="center"
flexDirection="row"
columnGap={4}
justifyContent="center"
width={250}
overflow="hidden"
>
{items.map((item, index) => (
<Bullet
key={item.props.metadata.id}
type={getItemStatus(index, isSmallCard ? carouselIndex + 1 : carouselIndex)}
/>
))}
</Flex>
);
};

export default Pagination;
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const Layout = ({ category, cards }: LayoutProps) => {
items={items}
styles={{
widthFactor: cardsSorted[0].carouselWidthFactor || WidthFactor.Full,
pagination: category.pagination,
pagination: category.hasPaggination,
}}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-mobile/src/dynamicContent/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type CategoryContentCard = ContentCardCommonProperties & {
cta?: string;
link?: string;
isDismissable?: boolean;
pagination?: boolean;
hasPaggination?: boolean;
};

type WalletContentCard = ContentCardCommonProperties & {
Expand Down
1 change: 1 addition & 0 deletions apps/ledger-live-mobile/src/dynamicContent/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const mapAsCategoryContentCard = (card: BrazeContentCard): CategoryConten
link: card.extras.link,
cta: card.extras.cta,
isDismissable: Boolean(card.extras.isDismissable && card.extras.isDismissable === "true"),
hasPaggination: Boolean(card.extras.hasPaggination && card.extras.hasPaggination === "true"),
});

export const mapAsWalletContentCard = (card: BrazeContentCard): WalletContentCard => ({
Expand Down

0 comments on commit 9cd49aa

Please sign in to comment.