This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
/
Language.tsx
98 lines (95 loc) · 2.94 KB
/
Language.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import React, {useCallback} from 'react';
import {TouchableOpacity, ScrollView} from 'react-native';
import {Box, Text, Icon, ToolbarWithClose} from 'components';
import {useCachedStorage} from 'services/StorageService';
import {useNavigation} from '@react-navigation/native';
import {SafeAreaView} from 'react-native-safe-area-context';
import {useI18n} from 'locale';
import styles from 'shared/Styles';
interface LanguageSelectItemProps {
onPress: () => void;
text: string;
isActive?: boolean;
lastItem?: boolean;
}
const LanguageSelectItem = ({onPress, text, lastItem, isActive}: LanguageSelectItemProps) => (
<>
<TouchableOpacity
activeOpacity={0.6}
onPress={onPress}
accessibilityRole="radio"
accessibilityState={{selected: isActive}}
>
<Box
paddingVertical="s"
marginHorizontal="-m"
paddingHorizontal="m"
borderRadius={5}
flexDirection="row"
alignContent="center"
justifyContent="space-between"
backgroundColor="infoBlockNeutralBackground"
>
<Text variant="bodyText" marginVertical="s" color="overlayBodyText">
{text}
</Text>
{isActive && (
<Box alignSelf="center">
<Icon size={32} name="icon-check" />
</Box>
)}
</Box>
</TouchableOpacity>
{!lastItem && <Box height={5} marginHorizontal="-m" backgroundColor="overlayBackground" />}
</>
);
export const LanguageScreen = () => {
const i18n = useI18n();
const navigation = useNavigation();
const close = useCallback(() => navigation.goBack(), [navigation]);
const {setLocale} = useCachedStorage();
const toggle = useCallback(
(newLocale: 'en' | 'fr') => () => {
setLocale(newLocale);
},
[setLocale],
);
return (
<Box backgroundColor="overlayBackground" flex={1}>
<SafeAreaView style={styles.flex}>
<ToolbarWithClose closeText={i18n.translate('LanguageSelect.Close')} showBackButton={false} onClose={close} />
<ScrollView>
<Text
paddingHorizontal="m"
variant="bodyTitle"
color="bodyText"
accessibilityRole="header"
accessibilityAutoFocus
>
{i18n.translate('LanguageSelect.Title')}
</Text>
<Box
marginHorizontal="m"
paddingHorizontal="m"
borderRadius={10}
overflow="hidden"
marginTop="m"
accessibilityRole="radiogroup"
>
<LanguageSelectItem
onPress={toggle('en')}
text={i18n.translate('LanguageSelect.En')}
isActive={i18n.locale === 'en'}
/>
<LanguageSelectItem
onPress={toggle('fr')}
text={i18n.translate('LanguageSelect.Fr')}
isActive={i18n.locale === 'fr'}
lastItem
/>
</Box>
</ScrollView>
</SafeAreaView>
</Box>
);
};