Skip to content

Commit 18a1aab

Browse files
authored
fix: mobile contest cards too narrow in Explore carousel (#14338)
1 parent 09a9e8b commit 18a1aab

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

packages/mobile/src/components/contest-card/ContestCard.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,7 @@ export const ContestCard = (props: ContestCardProps) => {
298298
onPress={handlePress}
299299
border='default'
300300
shadow='mid'
301-
// Floor the card at ~250px so the artist name + badges row in the
302-
// header doesn't clip on the narrowest carousels (the mobile
303-
// explore "Contests" rail was sized to whatever CardList default
304-
// — the QA pass flagged the cards as too skinny).
305-
style={{ overflow: 'hidden', borderRadius: 14, minWidth: 250 }}
301+
style={{ overflow: 'hidden', borderRadius: 14 }}
306302
{...other}
307303
>
308304
{/* Cover banner */}

packages/mobile/src/components/core/CardList.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export type CardListProps<ItemT> = Omit<FlatListProps<ItemT>, 'data'> & {
2525
// Use carousel spacing to override the parent's margins
2626
// e.g. make carousel start and end at edge of the screen
2727
carouselSpacing?: number
28+
29+
// Override the per-item slot width in horizontal mode. Defaults to
30+
// `spacing(43)` (172px), which is right for small thumbnail-style cards
31+
// (tracks, playlists) but too narrow for the redesigned contest card.
32+
horizontalCardWidth?: number | `${number}%`
2833
}
2934

3035
export type LoadingCard = { _loading: true }
@@ -60,12 +65,13 @@ const useStyles = makeStyles(({ spacing }) => ({
6065
flexGrow: 0
6166
},
6267
cardHorizontal: {
63-
width: spacing(43),
6468
paddingRight: spacing(3),
6569
paddingBottom: spacing(3)
6670
}
6771
}))
6872

73+
const DEFAULT_HORIZONTAL_CARD_WIDTH = 172
74+
6975
export function CardList<ItemT extends {}>(props: CardListProps<ItemT>) {
7076
const {
7177
renderItem,
@@ -78,6 +84,7 @@ export function CardList<ItemT extends {}>(props: CardListProps<ItemT>) {
7884
totalCount,
7985
horizontal: isHorizontal = false,
8086
carouselSpacing = 0,
87+
horizontalCardWidth = DEFAULT_HORIZONTAL_CARD_WIDTH,
8188
...other
8289
} = props
8390

@@ -109,7 +116,13 @@ export function CardList<ItemT extends {}>(props: CardListProps<ItemT>) {
109116
)
110117

111118
return (
112-
<View style={isHorizontal ? styles.cardHorizontal : styles.card}>
119+
<View
120+
style={
121+
isHorizontal
122+
? [styles.cardHorizontal, { width: horizontalCardWidth }]
123+
: styles.card
124+
}
125+
>
113126
{itemElement}
114127
</View>
115128
)
@@ -119,7 +132,8 @@ export function CardList<ItemT extends {}>(props: CardListProps<ItemT>) {
119132
renderItem,
120133
styles.card,
121134
styles.cardHorizontal,
122-
isHorizontal
135+
isHorizontal,
136+
horizontalCardWidth
123137
]
124138
)
125139

packages/mobile/src/screens/explore-screen/components/FeaturedRemixContests.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react'
22

33
import { useAllRemixContests } from '@audius/common/api'
44
import { exploreMessages as messages } from '@audius/common/messages'
5+
import { useWindowDimensions } from 'react-native'
56

67
import { useTheme } from '@audius/harmony-native'
78
import { ContestCard } from 'app/components/contest-card'
@@ -12,8 +13,16 @@ import { useDeferredElement } from '../../../hooks/useDeferredElement'
1213

1314
import { ExploreSection } from './ExploreSection'
1415

16+
// Carousel slot width for contest cards. The dedicated /contests screen
17+
// renders cards at roughly full screen width minus its horizontal margins;
18+
// the Explore carousel matches that visual width while leaving a small
19+
// peek of the next card to invite horizontal swipe.
20+
const CONTEST_CARD_PEEK = 48
21+
1522
export const FeaturedRemixContests = () => {
1623
const { spacing } = useTheme()
24+
const { width: windowWidth } = useWindowDimensions()
25+
const contestCardWidth = windowWidth - CONTEST_CARD_PEEK
1726
const { InViewWrapper, inView } = useDeferredElement()
1827

1928
const { data: allContestTrackIds, isPending: isAllContestsPending } =
@@ -27,6 +36,7 @@ export const FeaturedRemixContests = () => {
2736
renderItem={({ item }) => <ContestCard trackId={item.trackId} />}
2837
horizontal
2938
carouselSpacing={spacing.l}
39+
horizontalCardWidth={contestCardWidth}
3040
isLoading={isAllContestsPending}
3141
LoadingCardComponent={TrackCardSkeleton}
3242
/>

0 commit comments

Comments
 (0)