tooot/src/screens/Tabs/Me/Settings/App.tsx

166 lines
5.4 KiB
TypeScript
Raw Normal View History

2021-01-27 00:35:34 +01:00
import haptics from '@components/haptics'
import { MenuContainer, MenuRow } from '@components/Menu'
import { useActionSheet } from '@expo/react-native-action-sheet'
2021-02-20 19:12:44 +01:00
import { useNavigation } from '@react-navigation/native'
2021-03-28 23:31:10 +02:00
import { LOCALES } from '@root/i18n/locales'
2022-04-30 23:47:52 +02:00
import { useAppDispatch } from '@root/store'
2021-01-27 00:35:34 +01:00
import {
changeBrowser,
changeTheme,
getSettingsTheme,
2021-03-10 10:22:53 +01:00
getSettingsBrowser,
2022-02-12 14:51:01 +01:00
getSettingsFontsize,
getSettingsDarkTheme,
2022-05-13 00:04:15 +02:00
changeDarkTheme,
getSettingsStaticEmoji,
changeStaticEmoji
2021-01-27 00:35:34 +01:00
} from '@utils/slices/settingsSlice'
import * as Localization from 'expo-localization'
2021-01-28 01:14:00 +01:00
import React from 'react'
2021-01-27 00:35:34 +01:00
import { useTranslation } from 'react-i18next'
import { Linking, Platform } from 'react-native'
2022-04-30 23:47:52 +02:00
import { useSelector } from 'react-redux'
2021-05-09 21:59:03 +02:00
import { mapFontsizeToName } from '../SettingsFontsize'
2021-01-27 00:35:34 +01:00
const SettingsApp: React.FC = () => {
2021-08-29 15:25:38 +02:00
const navigation = useNavigation<any>()
2022-04-30 23:47:52 +02:00
const dispatch = useAppDispatch()
2021-01-27 00:35:34 +01:00
const { showActionSheetWithOptions } = useActionSheet()
2021-03-28 23:31:10 +02:00
const { t, i18n } = useTranslation('screenTabs')
2021-01-27 00:35:34 +01:00
2021-03-10 10:22:53 +01:00
const settingsFontsize = useSelector(getSettingsFontsize)
2021-01-27 00:35:34 +01:00
const settingsTheme = useSelector(getSettingsTheme)
2022-02-12 14:51:01 +01:00
const settingsDarkTheme = useSelector(getSettingsDarkTheme)
2021-01-27 00:35:34 +01:00
const settingsBrowser = useSelector(getSettingsBrowser)
2022-05-13 00:04:15 +02:00
const settingsStaticEmoji = useSelector(getSettingsStaticEmoji)
2021-02-08 23:47:20 +01:00
2021-01-27 00:35:34 +01:00
return (
<MenuContainer>
2021-05-09 21:59:03 +02:00
<MenuRow
title={t('me.settings.fontsize.heading')}
content={t(`me.settings.fontsize.content.${mapFontsizeToName(settingsFontsize)}`)}
2021-05-09 21:59:03 +02:00
iconBack='ChevronRight'
onPress={() => navigation.navigate('Tab-Me-Settings-Fontsize')}
2021-05-09 21:59:03 +02:00
/>
2021-01-27 00:35:34 +01:00
<MenuRow
2021-03-28 23:31:10 +02:00
title={t('me.settings.language.heading')}
2022-11-17 20:02:56 +01:00
content={
// @ts-ignore
LOCALES[
Platform.OS === 'ios' ? Localization.locale.toLowerCase() : i18n.language.toLowerCase()
]
}
2021-01-27 00:35:34 +01:00
iconBack='ChevronRight'
onPress={() =>
Platform.OS === 'ios'
? Linking.openSettings()
: navigation.navigate('Tab-Me-Settings-Language')
}
2021-01-27 00:35:34 +01:00
/>
<MenuRow
2021-03-28 23:31:10 +02:00
title={t('me.settings.theme.heading')}
content={t(`me.settings.theme.options.${settingsTheme}`)}
2021-01-27 00:35:34 +01:00
iconBack='ChevronRight'
onPress={() =>
showActionSheetWithOptions(
{
2021-03-28 23:31:10 +02:00
title: t('me.settings.theme.heading'),
2021-01-27 00:35:34 +01:00
options: [
2021-03-28 23:31:10 +02:00
t('me.settings.theme.options.auto'),
t('me.settings.theme.options.light'),
t('me.settings.theme.options.dark'),
t('me.settings.theme.options.cancel')
2021-01-27 00:35:34 +01:00
],
cancelButtonIndex: 3
},
buttonIndex => {
switch (buttonIndex) {
case 0:
haptics('Success')
dispatch(changeTheme('auto'))
break
case 1:
haptics('Success')
dispatch(changeTheme('light'))
break
case 2:
haptics('Success')
dispatch(changeTheme('dark'))
2022-02-12 14:51:01 +01:00
break
}
}
)
}
/>
<MenuRow
title={t('me.settings.darkTheme.heading')}
content={t(`me.settings.darkTheme.options.${settingsDarkTheme}`)}
iconBack='ChevronRight'
onPress={() =>
showActionSheetWithOptions(
{
title: t('me.settings.darkTheme.heading'),
options: [
t('me.settings.darkTheme.options.lighter'),
t('me.settings.darkTheme.options.darker'),
t('me.settings.darkTheme.options.cancel')
],
cancelButtonIndex: 2
},
buttonIndex => {
switch (buttonIndex) {
case 0:
haptics('Success')
dispatch(changeDarkTheme('lighter'))
break
case 1:
haptics('Success')
dispatch(changeDarkTheme('darker'))
2021-01-27 00:35:34 +01:00
break
}
}
)
}
/>
<MenuRow
2021-03-28 23:31:10 +02:00
title={t('me.settings.browser.heading')}
content={t(`me.settings.browser.options.${settingsBrowser}`)}
2021-01-27 00:35:34 +01:00
iconBack='ChevronRight'
onPress={() =>
showActionSheetWithOptions(
{
2021-03-28 23:31:10 +02:00
title: t('me.settings.browser.heading'),
2021-01-27 00:35:34 +01:00
options: [
2021-03-28 23:31:10 +02:00
t('me.settings.browser.options.internal'),
t('me.settings.browser.options.external'),
t('me.settings.browser.options.cancel')
2021-01-27 00:35:34 +01:00
],
cancelButtonIndex: 2
},
buttonIndex => {
switch (buttonIndex) {
case 0:
haptics('Success')
dispatch(changeBrowser('internal'))
break
case 1:
haptics('Success')
dispatch(changeBrowser('external'))
break
}
}
)
}
/>
2022-05-13 00:04:15 +02:00
<MenuRow
title={t('me.settings.staticEmoji.heading')}
description={t('me.settings.staticEmoji.description')}
switchValue={settingsStaticEmoji}
2022-11-29 23:44:11 +01:00
switchOnValueChange={() => dispatch(changeStaticEmoji(!settingsStaticEmoji))}
2022-05-13 00:04:15 +02:00
/>
2021-01-27 00:35:34 +01:00
</MenuContainer>
)
}
export default SettingsApp