1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Hashtag done

This commit is contained in:
Zhiyuan Zheng
2020-12-04 01:17:10 +01:00
parent 5866d016bc
commit fcaea5b8d9
9 changed files with 424 additions and 334 deletions

View File

@ -0,0 +1,71 @@
import React, { Dispatch, RefObject } from 'react'
import { StyleSheet, Text, TextInput } from 'react-native'
import { StyleConstants } from 'src/utils/styles/constants'
import { useTheme } from 'src/utils/styles/ThemeManager'
import { PostAction, PostState } from '../Compose'
import formatText from './formatText'
export interface Props {
postState: PostState
postDispatch: Dispatch<PostAction>
textInputRef: RefObject<TextInput>
}
const ComposeTextInput: React.FC<Props> = ({
postState,
postDispatch,
textInputRef
}) => {
const { theme } = useTheme()
return (
<TextInput
style={[
styles.textInput,
{
color: theme.primary
}
]}
autoCapitalize='none'
autoCorrect={false}
autoFocus
enablesReturnKeyAutomatically
multiline
placeholder='想说点什么'
placeholderTextColor={theme.secondary}
onChangeText={content =>
formatText({
postDispatch,
content
})
}
onSelectionChange={({
nativeEvent: {
selection: { start, end }
}
}) => {
postDispatch({ type: 'selection', payload: { start, end } })
}}
ref={textInputRef}
scrollEnabled
>
<Text>{postState.text.formatted}</Text>
</TextInput>
)
}
const styles = StyleSheet.create({
textInput: {
fontSize: StyleConstants.Font.Size.M,
marginTop: StyleConstants.Spacing.S,
marginBottom: StyleConstants.Spacing.M,
paddingLeft: StyleConstants.Spacing.Global.PagePadding,
paddingRight: StyleConstants.Spacing.Global.PagePadding
}
})
export default React.memo(
ComposeTextInput,
(prev, next) =>
prev.postState.text.formatted === next.postState.text.formatted
)