mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at ruby-v 2.3 kB view raw
1import React from 'react' 2import {View} from 'react-native' 3import RNPickerSelect, {PickerSelectProps} from 'react-native-picker-select' 4import {useQueryClient} from '@tanstack/react-query' 5 6import {sanitizeAppLanguageSetting} from '#/locale/helpers' 7import {APP_LANGUAGES} from '#/locale/languages' 8import {useLanguagePrefs, useLanguagePrefsApi} from '#/state/preferences' 9import {resetPostsFeedQueries} from '#/state/queries/post-feed' 10import {atoms as a, useTheme, ViewStyleProp} from '#/alf' 11import {ChevronBottom_Stroke2_Corner0_Rounded as ChevronDown} from '#/components/icons/Chevron' 12 13export function AppLanguageDropdown(_props: ViewStyleProp) { 14 const t = useTheme() 15 16 const queryClient = useQueryClient() 17 const langPrefs = useLanguagePrefs() 18 const setLangPrefs = useLanguagePrefsApi() 19 const sanitizedLang = sanitizeAppLanguageSetting(langPrefs.appLanguage) 20 21 const onChangeAppLanguage = React.useCallback( 22 (value: Parameters<PickerSelectProps['onValueChange']>[0]) => { 23 if (!value) return 24 if (sanitizedLang !== value) { 25 setLangPrefs.setAppLanguage(sanitizeAppLanguageSetting(value)) 26 } 27 28 // reset feeds to refetch content 29 resetPostsFeedQueries(queryClient) 30 }, 31 [sanitizedLang, setLangPrefs, queryClient], 32 ) 33 34 return ( 35 <View style={a.relative}> 36 <RNPickerSelect 37 darkTheme={t.scheme === 'dark'} 38 placeholder={{}} 39 value={sanitizedLang} 40 onValueChange={onChangeAppLanguage} 41 items={APP_LANGUAGES.filter(l => Boolean(l.code2)).map(l => ({ 42 label: l.name, 43 value: l.code2, 44 key: l.code2, 45 }))} 46 useNativeAndroidPickerStyle={false} 47 style={{ 48 inputAndroid: { 49 color: t.atoms.text_contrast_medium.color, 50 fontSize: 16, 51 paddingRight: 12 + 4, 52 }, 53 inputIOS: { 54 color: t.atoms.text.color, 55 fontSize: 16, 56 paddingRight: 12 + 4, 57 }, 58 }} 59 /> 60 61 <View 62 style={[ 63 a.absolute, 64 a.inset_0, 65 {left: 'auto'}, 66 {pointerEvents: 'none'}, 67 a.align_center, 68 a.justify_center, 69 ]}> 70 <ChevronDown fill={t.atoms.text.color} size="xs" /> 71 </View> 72 </View> 73 ) 74}