tooot/src/screens/Shared/Compose/SpoilerInput.tsx

71 lines
1.8 KiB
TypeScript
Raw Normal View History

import React, { useContext } from 'react'
2020-12-06 23:51:13 +01:00
import { StyleSheet, Text, TextInput } from 'react-native'
2020-12-13 14:04:25 +01:00
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
import { ComposeContext } from '@screens/Shared/Compose'
2020-12-06 23:51:13 +01:00
import formatText from './formatText'
const ComposeSpoilerInput: React.FC = () => {
const { composeState, composeDispatch } = useContext(ComposeContext)
2020-12-06 23:51:13 +01:00
const { theme } = useTheme()
return (
<TextInput
style={[
styles.spoilerInput,
{
color: theme.primary,
borderBottomColor: theme.border
}
]}
autoCapitalize='none'
autoCorrect={false}
autoFocus
enablesReturnKeyAutomatically
multiline
placeholder='折叠部分的警告信息'
placeholderTextColor={theme.secondary}
onChangeText={content =>
formatText({
textInput: 'spoiler',
2020-12-07 12:31:40 +01:00
composeDispatch,
2020-12-06 23:51:13 +01:00
content
})
}
onSelectionChange={({
nativeEvent: {
selection: { start, end }
}
}) => {
2020-12-07 12:31:40 +01:00
composeDispatch({
2020-12-06 23:51:13 +01:00
type: 'spoiler',
payload: { selection: { start, end } }
})
}}
ref={composeState.textInputFocus.refs.spoiler}
2020-12-06 23:51:13 +01:00
scrollEnabled
2020-12-26 00:40:27 +01:00
onFocus={() =>
composeDispatch({
type: 'textInputFocus',
payload: { current: 'spoiler' }
})
}
2020-12-06 23:51:13 +01:00
>
2020-12-07 12:31:40 +01:00
<Text>{composeState.spoiler.formatted}</Text>
2020-12-06 23:51:13 +01:00
</TextInput>
)
}
const styles = StyleSheet.create({
spoilerInput: {
fontSize: StyleConstants.Font.Size.M,
marginTop: StyleConstants.Spacing.S,
paddingBottom: StyleConstants.Spacing.M,
marginLeft: StyleConstants.Spacing.Global.PagePadding,
marginRight: StyleConstants.Spacing.Global.PagePadding,
borderBottomWidth: 0.5
}
})
export default ComposeSpoilerInput