tooot/src/screens/Tabs/Me/SettingsLanguage.tsx

56 lines
1.7 KiB
TypeScript
Raw Normal View History

import haptics from '@components/haptics'
2022-12-15 18:43:39 +01:00
import { MenuRow } from '@components/Menu'
import { LOCALES } from '@root/i18n/locales'
import { TabMeStackScreenProps } from '@utils/navigation/navigators'
import { setChannels } from '@utils/slices/instances/push/utils'
import { getInstances } from '@utils/slices/instancesSlice'
import { changeLanguage } from '@utils/slices/settingsSlice'
2022-12-15 18:43:39 +01:00
import { StyleConstants } from '@utils/styles/constants'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { FlatList, Platform } from 'react-native'
import { useDispatch, useSelector } from 'react-redux'
2022-12-09 21:09:00 +01:00
const TabMeSettingsLanguage: React.FC<TabMeStackScreenProps<'Tab-Me-Settings-Language'>> = ({
navigation
}) => {
const { i18n } = useTranslation('screenTabs')
const languages = Object.entries(LOCALES)
const instances = useSelector(getInstances)
const dispatch = useDispatch()
const change = (lang: string) => {
haptics('Success')
dispatch(changeLanguage(lang))
i18n.changeLanguage(lang)
// Update Android notification channel language
if (Platform.OS === 'android') {
2022-12-21 15:24:23 +01:00
instances.forEach(instance => setChannels(instance, true))
}
2022-05-29 01:57:15 +02:00
navigation.pop(1)
}
return (
2022-12-15 18:43:39 +01:00
<FlatList
style={{ flex: 1, paddingHorizontal: StyleConstants.Spacing.Global.PagePadding }}
data={languages}
renderItem={({ item }) => {
return (
<MenuRow
key={item[0]}
title={item[1]}
iconBack={item[0] === i18n.language ? 'Check' : undefined}
iconBackColor={'blue'}
onPress={() => item[0] !== i18n.language && change(item[0])}
/>
)
}}
/>
)
}
export default TabMeSettingsLanguage