Skip to content

Commit 74e7358

Browse files
Fix mobile track artist centering
1 parent 84dddd5 commit 74e7358

9 files changed

Lines changed: 132 additions & 22 deletions

File tree

packages/mobile/src/components/lineup-tile/LineupTileMetadata.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import { useSelector } from 'react-redux'
55

66
import { IconVolumeLevel2 } from '@audius/harmony-native'
77
import { Text, FadeInView } from 'app/components/core'
8-
import { UserLink } from 'app/components/user-link'
8+
import { UserBadges } from 'app/components/user-badges'
99
import { useNavigation } from 'app/hooks/useNavigation'
1010
import { makeStyles } from 'app/styles'
1111
import type { GestureResponderHandler } from 'app/types/gesture'
1212
import { useThemeColors } from 'app/utils/theme'
1313

1414
import { LineupTileArt } from './LineupTileArt'
1515
import { LineupTileTopRight } from './LineupTileTopRight'
16+
import type { ArtistNameCollaborator } from './artistNames'
17+
import { getTrackArtistNames } from './artistNames'
1618
import { useStyles as useTileStyles } from './styles'
1719
import type { RenderImage } from './types'
1820

@@ -27,6 +29,9 @@ const useStyles = makeStyles(({ palette }) => ({
2729
playingIndicator: {
2830
marginLeft: 8
2931
},
32+
artistText: {
33+
flexShrink: 1
34+
},
3035
coSignLabel: {
3136
position: 'absolute',
3237
bottom: -3,
@@ -45,6 +50,8 @@ type Props = {
4550
renderImage: RenderImage
4651
title: string
4752
userId: ID
53+
userName: string
54+
collaborators?: ArtistNameCollaborator[] | null
4855
isPlayingUid: boolean
4956
type: 'track' | 'playlist' | 'album'
5057
trackId: ID
@@ -59,6 +66,8 @@ export const LineupTileMetadata = ({
5966
renderImage,
6067
title,
6168
userId,
69+
userName,
70+
collaborators,
6271
isPlayingUid,
6372
type,
6473
trackId,
@@ -72,6 +81,7 @@ export const LineupTileMetadata = ({
7281
const navigation = useNavigation()
7382

7483
const isActive = isPlayingUid
84+
const artistNames = getTrackArtistNames(userName, collaborators)
7585

7686
const isPlaying = useSelector((state) => {
7787
return getPlaying(state) && isActive
@@ -139,15 +149,17 @@ export const LineupTileMetadata = ({
139149
onPressIn={onPressWithPropagationBlock}
140150
onPress={handlePressArtist}
141151
activeOpacity={0.7}
142-
style={{ alignSelf: 'flex-start' }}
152+
style={tileStyles.artist}
143153
>
144-
<View pointerEvents='none'>
145-
<UserLink
146-
variant={isActive ? 'active' : 'default'}
147-
textVariant='body'
148-
userId={userId}
149-
/>
150-
</View>
154+
<Text
155+
color={isActive ? 'primary' : 'neutral'}
156+
numberOfLines={1}
157+
ellipsizeMode='tail'
158+
style={styles.artistText}
159+
>
160+
{artistNames}
161+
</Text>
162+
<UserBadges userId={userId} />
151163
</TouchableOpacity>
152164
</FadeInView>
153165
<LineupTileTopRight

packages/mobile/src/components/lineup-tile/TrackTile.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const TrackTileComponent = (props: TrackTileProps) => {
8585
title: track.title,
8686
track_id: track.track_id,
8787
genre: track.genre,
88+
collaborators: track.collaborators,
8889
stream_conditions: track.stream_conditions,
8990

9091
ddex_app: track.ddex_app,
@@ -100,6 +101,7 @@ const TrackTileComponent = (props: TrackTileProps) => {
100101
const { data: user } = useUser(track?.owner_id, {
101102
select: (user) => ({
102103
artist_pick_track_id: user.artist_pick_track_id,
104+
name: user.name,
103105
user_id: user.user_id,
104106
is_deactivated: user.is_deactivated
105107
})
@@ -309,6 +311,8 @@ const TrackTileComponent = (props: TrackTileProps) => {
309311
onPressWithPropagationBlock={handlePressWithPropagationBlock}
310312
title={track.title}
311313
userId={user.user_id}
314+
userName={user.name}
315+
collaborators={track.collaborators}
312316
isPlayingUid={isPlayingUid}
313317
type='track'
314318
trackId={track.track_id}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { getTrackArtistNames } from './artistNames'
2+
3+
describe('getTrackArtistNames', () => {
4+
it('combines owner and collaborator names', () => {
5+
expect(
6+
getTrackArtistNames('ray61626b', [{ name: 'dj g8r' }, { name: 'tim' }])
7+
).toBe('ray61626b, dj g8r, tim')
8+
})
9+
10+
it('omits missing collaborator names', () => {
11+
expect(
12+
getTrackArtistNames('ray61626b', [
13+
{ name: null },
14+
{ name: undefined },
15+
{ name: 'dj g8r' }
16+
])
17+
).toBe('ray61626b, dj g8r')
18+
})
19+
})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export type ArtistNameCollaborator = {
2+
name?: string | null
3+
}
4+
5+
export const getTrackArtistNames = (
6+
userName: string,
7+
collaborators?: ArtistNameCollaborator[] | null
8+
) => {
9+
const collaboratorNames =
10+
collaborators?.map((collaborator) => collaborator.name).filter(Boolean) ??
11+
[]
12+
13+
return [userName, ...collaboratorNames].join(', ')
14+
}

packages/mobile/src/components/lineup-tile/styles.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export const useStyles = makeStyles(({ palette }) => ({
5656
},
5757
artist: {
5858
...flexRowCentered(),
59+
justifyContent: 'flex-start',
60+
gap: spacing(1),
61+
width: '100%',
5962
marginBottom: 'auto',
6063
paddingRight: spacing(10),
6164
minHeight: 20
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { render, screen } from '@testing-library/react-native'
2+
3+
import { TrackArtists } from './TrackArtists'
4+
5+
jest.mock(
6+
'@audius/harmony-native',
7+
() => {
8+
const React = require('react')
9+
const { Text, View } = require('react-native')
10+
11+
return {
12+
Flex: ({ children, style }: any) =>
13+
React.createElement(View, { style }, children),
14+
Text: ({ children }: any) => React.createElement(Text, null, children)
15+
}
16+
},
17+
{ virtual: true }
18+
)
19+
20+
jest.mock('./UserLink', () => {
21+
const React = require('react')
22+
const { Text } = require('react-native')
23+
24+
return {
25+
UserLink: ({
26+
hideBadges,
27+
userId
28+
}: {
29+
hideBadges?: boolean
30+
userId: number
31+
}) =>
32+
React.createElement(
33+
Text,
34+
null,
35+
`${userId}:${hideBadges ? 'badges-hidden' : 'badges-visible'}`
36+
)
37+
}
38+
})
39+
40+
describe('TrackArtists', () => {
41+
it('hides inline badges so the artist names stay centered', () => {
42+
render(<TrackArtists userId={1} collaborators={[{ user_id: 2 }]} />)
43+
44+
expect(screen.getByText('1:badges-hidden')).toBeOnTheScreen()
45+
expect(screen.getByText('2:badges-hidden')).toBeOnTheScreen()
46+
expect(screen.queryByText(/badges-visible/)).toBeNull()
47+
})
48+
})

packages/mobile/src/components/user-link/TrackArtists.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,19 @@ export const CollaboratorLinks = ({
4545
)
4646
}
4747

48-
type TrackArtistsProps = Omit<ComponentProps<typeof UserLink>, 'style'> & {
48+
type TrackArtistsProps = Omit<
49+
ComponentProps<typeof UserLink>,
50+
'style' | 'hideBadges'
51+
> & {
4952
/** Accepted collaborator artists embedded on the track. */
5053
collaborators?: Collaborator[] | null
5154
style?: StyleProp<ViewStyle>
5255
}
5356

5457
/**
55-
* A track's artist line for mobile: the owner `<UserLink>` plus accepted
56-
* collaborators. With the flag off (or no collaborators) it renders just the
57-
* owner — a safe drop-in for an existing owner `<UserLink>`.
58+
* A track's centered artist line for mobile: the owner `<UserLink>` plus
59+
* accepted collaborators. Inline user badges are omitted here so the names,
60+
* rather than names plus badge width, stay visually centered.
5861
*/
5962
export const TrackArtists = ({
6063
collaborators,
@@ -69,8 +72,12 @@ export const TrackArtists = ({
6972
w='100%'
7073
style={[styles.artistRow, style]}
7174
>
72-
<UserLink {...userLinkProps} style={styles.artistLink} />
73-
<CollaboratorLinks collaborators={collaborators} {...userLinkProps} />
75+
<UserLink {...userLinkProps} hideBadges style={styles.artistLink} />
76+
<CollaboratorLinks
77+
collaborators={collaborators}
78+
{...userLinkProps}
79+
hideBadges
80+
/>
7481
</Flex>
7582
)
7683
}

packages/mobile/src/components/user-link/UserLink.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type UserLinkProps = Omit<TextLinkProps<ParamList>, 'to' | 'children'> & {
2424
badgeSize?: IconSize
2525
textLinkStyle?: StyleProp<TextStyle>
2626
disabled?: boolean
27+
hideBadges?: boolean
2728
hideFanClubBadge?: boolean
2829
mint?: string
2930
}
@@ -35,6 +36,7 @@ export const UserLink = (props: UserLinkProps) => {
3536
style,
3637
textLinkStyle,
3738
disabled,
39+
hideBadges,
3840
hideFanClubBadge,
3941
mint,
4042
...other
@@ -89,12 +91,14 @@ export const UserLink = (props: UserLinkProps) => {
8991
>
9092
{userName}
9193
</TextLink>
92-
<UserBadges
93-
userId={userId}
94-
badgeSize={badgeSize}
95-
mint={mint}
96-
hideFanClubBadge={hideFanClubBadge}
97-
/>
94+
{hideBadges ? null : (
95+
<UserBadges
96+
userId={userId}
97+
badgeSize={badgeSize}
98+
mint={mint}
99+
hideFanClubBadge={hideFanClubBadge}
100+
/>
101+
)}
98102
</AnimatedFlex>
99103
</Pressable>
100104
)

packages/mobile/src/screens/track-screen/TrackScreenDetailsTile.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,6 @@ export const TrackScreenDetailsTile = ({
630630
userId={user.user_id}
631631
collaborators={collaborators}
632632
size='l'
633-
badgeSize='s'
634633
style={{ justifyContent: 'center' }}
635634
/>
636635
) : null}

0 commit comments

Comments
 (0)