1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
Files
tooot/src/screens/Compose/Root/Header/SpoilerInput.tsx
xmflsct 1ea6aff328 619 restructure local storage (#628)
* To MMKV migration working

* POC migrated font size settings

* Moved settings to mmkv

* Fix typos

* Migrated contexts slice

* Migrated app slice

* POC instance emoji update

* Migrated drafts

* Migrated simple instance properties

* All migrated!

* Re-structure files

* Tolerant of undefined settings

* Can properly logging in and out including empty state
2022-12-28 23:41:36 +01:00

77 lines
2.5 KiB
TypeScript

import CustomText from '@components/Text'
import { useGlobalStorage } from '@utils/storage/actions'
import { StyleConstants } from '@utils/styles/constants'
import { adaptiveScale } from '@utils/styles/scaling'
import { useTheme } from '@utils/styles/ThemeManager'
import React, { useContext } from 'react'
import { useTranslation } from 'react-i18next'
import { TextInput } from 'react-native'
import ComposeContext from '../../utils/createContext'
import { formatText } from '../../utils/processText'
const ComposeSpoilerInput: React.FC = () => {
const { composeState, composeDispatch } = useContext(ComposeContext)
const { t } = useTranslation('screenCompose')
const { colors, mode } = useTheme()
const [adaptiveFontsize] = useGlobalStorage.number('app.font_size')
const adaptedFontsize = adaptiveScale(StyleConstants.Font.Size.M, adaptiveFontsize)
const adaptedLineheight = adaptiveScale(StyleConstants.Font.LineHeight.M, adaptiveFontsize)
return (
<TextInput
ref={composeState.textInputFocus.refs.spoiler}
keyboardAppearance={mode}
style={{
...StyleConstants.FontStyle.M,
marginTop: StyleConstants.Spacing.S,
paddingBottom: StyleConstants.Spacing.M,
marginLeft: StyleConstants.Spacing.Global.PagePadding,
marginRight: StyleConstants.Spacing.Global.PagePadding,
borderBottomWidth: 0.5,
color: colors.primaryDefault,
borderBottomColor: colors.border,
fontSize: adaptedFontsize,
lineHeight: adaptedLineheight
}}
autoFocus
enablesReturnKeyAutomatically
multiline
placeholder={t('content.root.header.spoilerInput.placeholder')}
placeholderTextColor={colors.secondary}
onChangeText={content =>
formatText({
textInput: 'spoiler',
composeDispatch,
content
})
}
onSelectionChange={({
nativeEvent: {
selection: { start, end }
}
}) => {
composeDispatch({
type: 'spoiler',
payload: { selection: { start, end } }
})
}}
scrollEnabled={false}
onFocus={() => {
composeDispatch({
type: 'textInputFocus',
payload: { current: 'spoiler' }
})
composeState.textInputFocus.isFocused.spoiler.current = true
}}
onBlur={() => {
composeState.textInputFocus.isFocused.spoiler.current = false
}}
>
<CustomText>{composeState.spoiler.formatted}</CustomText>
</TextInput>
)
}
export default ComposeSpoilerInput