Skip to content

Commit a2e7b7f

Browse files
authored
[PE-6115] Fix submissions label wrap on mobile remix contest section (#12002)
1 parent e0cfb31 commit a2e7b7f

File tree

1 file changed

+73
-33
lines changed

1 file changed

+73
-33
lines changed

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

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import React, { useEffect, useMemo, useState } from 'react'
1+
import React, { useCallback, useEffect, useMemo, useState } from 'react'
22
import type { RefObject } from 'react'
33

44
import { useRemixContest, useTrack, useCurrentUserId } from '@audius/common/api'
55
import type { ID } from '@audius/common/models'
6+
import { css } from '@emotion/native'
67
import type { FlatList } from 'react-native'
78
import Animated, {
89
useAnimatedStyle,
910
useSharedValue,
1011
withTiming
1112
} from 'react-native-reanimated'
1213
import { TabView, SceneMap, TabBar, TabBarItem } from 'react-native-tab-view'
14+
import type { Props as TabBarItemProps } from 'react-native-tab-view/lib/typescript/src/TabBarItem'
1315
import { usePrevious } from 'react-use'
1416

15-
import { Paper } from '@audius/harmony-native'
17+
import { Flex, Paper, Text } from '@audius/harmony-native'
1618
import { TabBody } from 'app/components/core/TabBody'
1719
import { makeStyles } from 'app/styles'
1820
import { useThemeColors } from 'app/utils/theme'
@@ -26,18 +28,18 @@ const TAB_FOOTER_HEIGHT = 64
2628
const TAB_HEADER_HEIGHT = 48
2729
const HEIGHT_OFFSET = 24
2830

31+
const messages = {
32+
submissions: 'Submissions',
33+
details: 'Details',
34+
prizes: 'Prizes'
35+
}
36+
2937
const useStyles = makeStyles(({ palette, typography, spacing }) => ({
3038
tabBar: {
3139
backgroundColor: 'transparent',
3240
height: spacing(10),
3341
marginHorizontal: spacing(4)
3442
},
35-
tabLabel: {
36-
marginHorizontal: 0,
37-
textTransform: 'none',
38-
fontFamily: typography.fontByWeight.demiBold,
39-
fontSize: typography.fontSize.medium
40-
},
4143
tabIndicator: {
4244
backgroundColor: palette.secondary,
4345
borderBottomLeftRadius: 20,
@@ -98,9 +100,9 @@ export const RemixContestSection = ({
98100

99101
useEffect(() => {
100102
setRoutes([
101-
{ key: 'details', title: 'Details' },
102-
...(hasPrizeInfo ? [{ key: 'prizes', title: 'Prizes' }] : []),
103-
{ key: 'submissions', title: 'Submissions' }
103+
{ key: 'details', title: messages.details },
104+
...(hasPrizeInfo ? [{ key: 'prizes', title: messages.prizes }] : []),
105+
{ key: 'submissions', title: messages.submissions }
104106
])
105107
}, [hasPrizeInfo])
106108

@@ -165,28 +167,66 @@ export const RemixContestSection = ({
165167
[scrollRef]
166168
)
167169

168-
const renderTabBar = (props: any) => (
169-
<TabBar
170-
{...props}
171-
style={styles.tabBar}
172-
labelStyle={styles.tabLabel}
173-
indicatorStyle={styles.tabIndicator}
174-
activeColor={neutral}
175-
inactiveColor={textIconSubdued}
176-
pressColor='transparent'
177-
pressOpacity={0.7}
178-
renderTabBarItem={({ route, key, ...restProps }) => (
179-
<TabBarItem
180-
{...restProps}
181-
key={key}
182-
route={route}
183-
getAccessibilityLabel={() => route.title}
184-
getAccessible={() => true}
185-
getLabelText={() => route.title}
186-
getTestID={() => `tab-${route.key}`}
187-
/>
188-
)}
189-
/>
170+
const renderLabel = useCallback(
171+
({ route, focused }: { route: Route; focused: boolean }) => {
172+
if (route.title === messages.submissions) {
173+
return (
174+
// Needed for small screens - otherwise the text is cut off
175+
<Flex style={css({ minWidth: 100 })}>
176+
<Text
177+
variant='body'
178+
strength='strong'
179+
color={focused ? 'default' : 'subdued'}
180+
>
181+
{route.title}
182+
</Text>
183+
</Flex>
184+
)
185+
}
186+
return (
187+
<Text
188+
variant='body'
189+
strength='strong'
190+
color={focused ? 'default' : 'subdued'}
191+
>
192+
{route.title}
193+
</Text>
194+
)
195+
},
196+
[]
197+
)
198+
199+
const renderTabBarItem = useCallback(
200+
// Weird type issue with TabBarItem, need to pass key prop. Otherwise we get:
201+
// Warning: A props object containing a "key" prop is being spread into JSX:
202+
({ route, key, ...props }: TabBarItemProps<Route> & { key: string }) => (
203+
<TabBarItem key={key} route={route} {...props} />
204+
),
205+
[]
206+
)
207+
208+
const renderTabBar = useCallback(
209+
(props: any) => (
210+
<TabBar
211+
{...props}
212+
style={styles.tabBar}
213+
indicatorStyle={styles.tabIndicator}
214+
activeColor={neutral}
215+
inactiveColor={textIconSubdued}
216+
pressColor='transparent'
217+
pressOpacity={0.7}
218+
renderLabel={renderLabel}
219+
renderTabBarItem={renderTabBarItem}
220+
/>
221+
),
222+
[
223+
styles.tabBar,
224+
styles.tabIndicator,
225+
neutral,
226+
textIconSubdued,
227+
renderLabel,
228+
renderTabBarItem
229+
]
190230
)
191231

192232
if (!remixContest) return null

0 commit comments

Comments
 (0)