|
| 1 | +import { useCallback } from 'react'; |
| 2 | +import { FlatList, Pressable, View } from 'react-native'; |
| 3 | +import { createStyleSheet, useStyles } from 'react-native-unistyles'; |
| 4 | + |
| 5 | +import HeaderWithBack from '@/components/shared/header-with-back'; |
| 6 | +import ScreenBackground from '@/components/shared/screen-background'; |
| 7 | +import Text from '@/components/ui/text'; |
| 8 | +import { useChangeLangOnUnmount } from '@/language/useChangeLangOnUnmount'; |
| 9 | +import { useLang } from '@/language/useLang'; |
| 10 | +import { hex2rgba } from '@/utils/ui.utils'; |
| 11 | + |
| 12 | +interface Option { |
| 13 | + key: string; |
| 14 | + label: string; |
| 15 | +} |
| 16 | + |
| 17 | +const options: Option[] = [ |
| 18 | + { key: 'es', label: 'Español' }, |
| 19 | + { key: 'en', label: 'English' }, |
| 20 | + { key: 'pt', label: 'Português' }, |
| 21 | + { key: 'fr', label: 'Français' }, |
| 22 | + { key: 'it', label: 'Italiano' }, |
| 23 | +]; |
| 24 | + |
| 25 | +const LanguageScreen = () => { |
| 26 | + const { styles } = useStyles(stylesheet); |
| 27 | + useChangeLangOnUnmount(); |
| 28 | + const { changeLanguage, currentLanguage, t } = useLang(); |
| 29 | + const renderItem = useCallback( |
| 30 | + ({ item }: { item: Option }) => ( |
| 31 | + <Pressable |
| 32 | + onPress={() => changeLanguage(item.key)} |
| 33 | + style={styles.option} |
| 34 | + disabled={currentLanguage === item.key} |
| 35 | + > |
| 36 | + <Text size={17}>{`${item.label} ${ |
| 37 | + currentLanguage === item.key ? `(${t('current')})` : '' |
| 38 | + }`}</Text> |
| 39 | + </Pressable> |
| 40 | + ), |
| 41 | + [styles, changeLanguage, currentLanguage, t], |
| 42 | + ); |
| 43 | + const spacer = useCallback( |
| 44 | + () => <View style={styles.spacer} />, |
| 45 | + [styles.spacer], |
| 46 | + ); |
| 47 | + |
| 48 | + return ( |
| 49 | + <> |
| 50 | + <View style={styles.container}> |
| 51 | + <HeaderWithBack title={'language'} /> |
| 52 | + <ScreenBackground /> |
| 53 | + <FlatList |
| 54 | + data={options} |
| 55 | + ItemSeparatorComponent={spacer} |
| 56 | + renderItem={renderItem} |
| 57 | + contentContainerStyle={styles.content} |
| 58 | + /> |
| 59 | + </View> |
| 60 | + </> |
| 61 | + ); |
| 62 | +}; |
| 63 | + |
| 64 | +export default LanguageScreen; |
| 65 | + |
| 66 | +const stylesheet = createStyleSheet((theme) => ({ |
| 67 | + container: { |
| 68 | + flex: 1, |
| 69 | + backgroundColor: '#2A3164', |
| 70 | + gap: 20, |
| 71 | + }, |
| 72 | + content: { |
| 73 | + backgroundColor: hex2rgba('#191E47', 0.8), |
| 74 | + padding: 20, |
| 75 | + borderRadius: 20, |
| 76 | + marginHorizontal: theme.sizes.screenPadding, |
| 77 | + }, |
| 78 | + option: { |
| 79 | + flexDirection: 'row', |
| 80 | + gap: 12, |
| 81 | + alignItems: 'center', |
| 82 | + }, |
| 83 | + spacer: { |
| 84 | + height: 2, |
| 85 | + width: '100%', |
| 86 | + marginVertical: 16, |
| 87 | + backgroundColor: '#2A3164', |
| 88 | + opacity: 0.34, |
| 89 | + }, |
| 90 | +})); |
0 commit comments