1
- import React , { useEffect , useMemo , useState } from 'react'
1
+ import React , { useCallback , useEffect , useMemo , useState } from 'react'
2
2
import type { RefObject } from 'react'
3
3
4
4
import { useRemixContest , useTrack , useCurrentUserId } from '@audius/common/api'
5
5
import type { ID } from '@audius/common/models'
6
+ import { css } from '@emotion/native'
6
7
import type { FlatList } from 'react-native'
7
8
import Animated , {
8
9
useAnimatedStyle ,
9
10
useSharedValue ,
10
11
withTiming
11
12
} from 'react-native-reanimated'
12
13
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'
13
15
import { usePrevious } from 'react-use'
14
16
15
- import { Paper } from '@audius/harmony-native'
17
+ import { Flex , Paper , Text } from '@audius/harmony-native'
16
18
import { TabBody } from 'app/components/core/TabBody'
17
19
import { makeStyles } from 'app/styles'
18
20
import { useThemeColors } from 'app/utils/theme'
@@ -26,18 +28,18 @@ const TAB_FOOTER_HEIGHT = 64
26
28
const TAB_HEADER_HEIGHT = 48
27
29
const HEIGHT_OFFSET = 24
28
30
31
+ const messages = {
32
+ submissions : 'Submissions' ,
33
+ details : 'Details' ,
34
+ prizes : 'Prizes'
35
+ }
36
+
29
37
const useStyles = makeStyles ( ( { palette, typography, spacing } ) => ( {
30
38
tabBar : {
31
39
backgroundColor : 'transparent' ,
32
40
height : spacing ( 10 ) ,
33
41
marginHorizontal : spacing ( 4 )
34
42
} ,
35
- tabLabel : {
36
- marginHorizontal : 0 ,
37
- textTransform : 'none' ,
38
- fontFamily : typography . fontByWeight . demiBold ,
39
- fontSize : typography . fontSize . medium
40
- } ,
41
43
tabIndicator : {
42
44
backgroundColor : palette . secondary ,
43
45
borderBottomLeftRadius : 20 ,
@@ -98,9 +100,9 @@ export const RemixContestSection = ({
98
100
99
101
useEffect ( ( ) => {
100
102
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 }
104
106
] )
105
107
} , [ hasPrizeInfo ] )
106
108
@@ -165,28 +167,66 @@ export const RemixContestSection = ({
165
167
[ scrollRef ]
166
168
)
167
169
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
+ ]
190
230
)
191
231
192
232
if ( ! remixContest ) return null
0 commit comments