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

71 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-12-26 00:40:27 +01:00
import React, { useCallback, useContext } from 'react'
2020-12-04 01:17:10 +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-04 01:17:10 +01:00
import formatText from './formatText'
const ComposeTextInput: React.FC = () => {
const { composeState, composeDispatch } = useContext(ComposeContext)
2020-12-04 01:17:10 +01:00
const { theme } = useTheme()
return (
<TextInput
style={[
styles.textInput,
{
2020-12-06 21:42:19 +01:00
color: theme.primary,
borderBottomColor: theme.border
2020-12-04 01:17:10 +01:00
}
]}
autoCapitalize='none'
autoCorrect={false}
autoFocus
enablesReturnKeyAutomatically
multiline
placeholder='想说点什么'
placeholderTextColor={theme.secondary}
onChangeText={content =>
formatText({
textInput: 'text',
2020-12-07 12:31:40 +01:00
composeDispatch,
2020-12-04 01:17:10 +01:00
content
})
}
onFocus={() =>
composeDispatch({
type: 'textInputFocus',
payload: { current: 'text' }
})
}
2020-12-04 01:17:10 +01:00
onSelectionChange={({
nativeEvent: {
selection: { start, end }
}
}) => {
2020-12-10 19:19:56 +01:00
composeDispatch({
type: 'text',
payload: { selection: { start, end } }
})
2020-12-04 01:17:10 +01:00
}}
ref={composeState.textInputFocus.refs.text}
2020-12-04 01:17:10 +01:00
scrollEnabled
>
2020-12-07 12:31:40 +01:00
<Text>{composeState.text.formatted}</Text>
2020-12-04 01:17:10 +01:00
</TextInput>
)
}
const styles = StyleSheet.create({
textInput: {
fontSize: StyleConstants.Font.Size.M,
marginTop: StyleConstants.Spacing.S,
2020-12-06 21:42:19 +01:00
paddingBottom: StyleConstants.Spacing.M,
marginLeft: StyleConstants.Spacing.Global.PagePadding,
2020-12-06 23:51:13 +01:00
marginRight: StyleConstants.Spacing.Global.PagePadding
2020-12-06 22:32:36 +01:00
// borderBottomWidth: 0.5
2020-12-04 01:17:10 +01:00
}
})
export default ComposeTextInput