2022-05-28 22:18:03 +02:00
|
|
|
import haptics from '@components/haptics'
|
2022-12-15 18:43:39 +01:00
|
|
|
import { MenuRow } from '@components/Menu'
|
2022-05-28 22:18:03 +02:00
|
|
|
import { LOCALES } from '@root/i18n/locales'
|
|
|
|
import { TabMeStackScreenProps } from '@utils/navigation/navigators'
|
2022-12-10 00:31:11 +01:00
|
|
|
import { setChannels } from '@utils/slices/instances/push/utils'
|
2022-05-28 22:18:03 +02:00
|
|
|
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'
|
2022-05-28 22:18:03 +02:00
|
|
|
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
|
|
|
|
}) => {
|
2022-12-10 00:31:11 +01:00
|
|
|
const { i18n } = useTranslation('screenTabs')
|
2022-05-28 22:18:03 +02:00
|
|
|
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-28 22:18:03 +02:00
|
|
|
}
|
2022-05-29 01:57:15 +02:00
|
|
|
|
|
|
|
navigation.pop(1)
|
2022-05-28 22:18:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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])}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
/>
|
2022-05-28 22:18:03 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TabMeSettingsLanguage
|