11import React from 'react' ;
22import { StyleSheet } from 'react-native' ;
33
4- interface HeaderWithBadgeProps {
5- platforms : ( 'android' | 'iOS' | 'web' ) [ ] ;
4+ type HeaderWithBadgeProps = {
5+ platforms : string [ ] ;
66 children ?: React . ReactNode ;
7- }
7+ } ;
8+
9+ type Platform = 'android' | 'ios' | 'web' ;
10+
11+ const platformNameMap : Record < Platform , string > = {
12+ android : 'Android' ,
13+ ios : 'iOS' ,
14+ web : 'Web' ,
15+ } ;
16+
17+ export function Badge ( { platform } : { platform : Platform } ) {
18+ let platformBadgeStyle ;
819
9- export function Badge ( { platform } : { platform : 'android' | 'iOS' | 'web' } ) {
10- const platformBadge =
11- platform === 'android'
12- ? styles . androidBadge
13- : platform === 'iOS'
14- ? styles . iosBadge
15- : platform === 'web'
16- ? styles . webBadge
17- : { } ;
20+ switch ( platform ) {
21+ case 'android' :
22+ platformBadgeStyle = styles . androidBadge ;
23+ break ;
24+ case 'ios' :
25+ platformBadgeStyle = styles . iosBadge ;
26+ break ;
27+ case 'web' :
28+ platformBadgeStyle = styles . webBadge ;
29+ break ;
30+ default :
31+ platformBadgeStyle = { } ;
32+ }
1833
19- return < div style = { { ...styles . badge , ...platformBadge } } > { platform } </ div > ;
34+ return (
35+ < div style = { { ...styles . badge , ...platformBadgeStyle } } >
36+ { platformNameMap [ platform ] }
37+ </ div >
38+ ) ;
2039}
2140
2241export default function HeaderWithBadge ( {
@@ -27,9 +46,12 @@ export default function HeaderWithBadge({
2746 < div style = { styles . container } >
2847 { children }
2948
30- { platforms . sort ( ) . map ( ( platform ) => (
31- < Badge key = { platform } platform = { platform } />
32- ) ) }
49+ { platforms
50+ . map ( ( platform ) => platform . toLowerCase ( ) as Platform )
51+ . sort ( )
52+ . map ( ( platform ) => (
53+ < Badge key = { platform } platform = { platform } />
54+ ) ) }
3355 </ div >
3456 ) ;
3557}
0 commit comments