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

158 lines
4.6 KiB
TypeScript
Raw Normal View History

2021-03-10 10:22:53 +01:00
import Button from '@components/Button'
import haptics from '@components/haptics'
import ComponentSeparator from '@components/Separator'
import CustomText from '@components/Text'
2021-03-10 10:22:53 +01:00
import TimelineDefault from '@components/Timeline/Default'
2021-08-29 15:25:38 +02:00
import { TabMeStackScreenProps } from '@utils/navigation/navigators'
import { useGlobalStorage } from '@utils/storage/actions'
import { StorageGlobal } from '@utils/storage/global'
2021-03-10 11:49:14 +01:00
import { StyleConstants } from '@utils/styles/constants'
import { adaptiveScale } from '@utils/styles/scaling'
2021-03-10 10:22:53 +01:00
import { useTheme } from '@utils/styles/ThemeManager'
import React from 'react'
2021-03-10 10:22:53 +01:00
import { useTranslation } from 'react-i18next'
2023-01-10 00:28:39 +01:00
import { View } from 'react-native'
2021-03-10 10:22:53 +01:00
import { ScrollView } from 'react-native-gesture-handler'
export const mapFontsizeToName = (size: StorageGlobal['app.font_size']) => {
2021-03-10 10:22:53 +01:00
switch (size) {
case -1:
return 'S'
case 0:
return 'M'
case 1:
return 'L'
case 2:
return 'XL'
case 3:
return 'XXL'
default:
return 'M'
2021-03-10 10:22:53 +01:00
}
}
2022-12-18 23:15:58 +01:00
const TabMeSettingsFontsize: React.FC<TabMeStackScreenProps<'Tab-Me-Settings-Fontsize'>> = () => {
const { colors } = useTheme()
2021-03-28 23:31:10 +02:00
const { t } = useTranslation('screenTabs')
const [fontSize, setFontSize] = useGlobalStorage.number('app.font_size')
2021-03-10 10:22:53 +01:00
const item = {
id: 'demo',
uri: 'https://tooot.app',
created_at: new Date(2021, 4, 16),
2021-03-10 10:22:53 +01:00
sensitive: false,
visibility: 'public',
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
favourited: true,
reblogged: false,
muted: false,
bookmarked: false,
2021-03-28 23:31:10 +02:00
content: t('me.fontSize.demo'),
2021-03-10 10:22:53 +01:00
reblog: null,
application: {
name: 'tooot',
website: 'https://tooot.app'
},
account: {
id: 'demo',
url: 'https://tooot.app',
username: 'tooot📱',
acct: 'tooot@xmflsct.com',
display_name: 'tooot📱',
avatar: 'https://avatars.githubusercontent.com/u/77554750?s=100',
2021-03-10 10:22:53 +01:00
avatar_static: 'https://avatars.githubusercontent.com/u/77554750?s=100'
},
media_attachments: [],
mentions: []
}
return (
<ScrollView>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
marginTop: StyleConstants.Spacing.M
}}
>
2021-03-10 10:22:53 +01:00
{([-1, 0, 1, 2, 3] as [-1, 0, 1, 2, 3]).map(size => (
<CustomText
2021-03-10 11:49:14 +01:00
key={size}
style={{
marginHorizontal: StyleConstants.Spacing.XS,
paddingHorizontal: StyleConstants.Spacing.XS,
marginBottom: StyleConstants.Spacing.M,
fontSize: adaptiveScale(StyleConstants.Font.Size.M, size),
lineHeight: adaptiveScale(StyleConstants.Font.LineHeight.M, size),
2022-12-29 23:03:23 +01:00
color: (fontSize || 0) === size ? colors.primaryDefault : colors.secondary,
2022-12-31 00:07:28 +01:00
borderWidth: 1,
borderColor: colors.border
}}
2022-12-29 23:03:23 +01:00
fontWeight={(fontSize || 0) === size ? 'Bold' : undefined}
2021-03-10 10:22:53 +01:00
>
2021-03-28 23:31:10 +02:00
{t(`me.fontSize.sizes.${mapFontsizeToName(size)}`)}
</CustomText>
2021-03-10 10:22:53 +01:00
))}
</View>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center'
}}
>
2021-03-10 10:22:53 +01:00
<Button
onPress={() => {
2022-12-29 23:03:23 +01:00
if ((fontSize || 0) > -1) {
2021-03-10 10:22:53 +01:00
haptics('Light')
2021-08-29 15:25:38 +02:00
// @ts-ignore
2022-12-29 23:03:23 +01:00
setFontSize((fontSize || 0) - 1)
2021-03-10 10:22:53 +01:00
}
}}
type='icon'
content='minus'
2021-03-10 10:22:53 +01:00
round
disabled={(fontSize || 0) <= -1}
style={{ marginHorizontal: StyleConstants.Spacing.S }}
2021-03-10 10:22:53 +01:00
/>
<Button
onPress={() => {
2022-12-29 23:03:23 +01:00
if ((fontSize || 0) < 3) {
2021-03-10 10:22:53 +01:00
haptics('Light')
2021-08-29 15:25:38 +02:00
// @ts-ignore
2022-12-29 23:03:23 +01:00
setFontSize((fontSize || 0) + 1)
2021-03-10 10:22:53 +01:00
}
}}
type='icon'
content='plus'
2021-03-10 10:22:53 +01:00
round
disabled={(fontSize || 0) >= 3}
style={{ marginHorizontal: StyleConstants.Spacing.S }}
2021-03-10 10:22:53 +01:00
/>
</View>
<View style={{ marginVertical: StyleConstants.Spacing.L }}>
2022-07-09 11:40:48 +02:00
<ComponentSeparator
extraMarginLeft={-StyleConstants.Spacing.Global.PagePadding}
extraMarginRight={-StyleConstants.Spacing.Global.PagePadding}
/>
<TimelineDefault
// @ts-ignore
item={item}
disableDetails
disableOnPress
/>
<ComponentSeparator
extraMarginLeft={-StyleConstants.Spacing.Global.PagePadding}
extraMarginRight={-StyleConstants.Spacing.Global.PagePadding}
/>
</View>
2021-03-10 10:22:53 +01:00
</ScrollView>
)
}
2021-05-09 21:59:03 +02:00
export default TabMeSettingsFontsize