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 textInputRef: RefObject } const ComposeTextInput: React.FC = ({ postState, postDispatch, textInputRef }) => { const { theme } = useTheme() return ( formatText({ postDispatch, content }) } onSelectionChange={({ nativeEvent: { selection: { start, end } } }) => { postDispatch({ type: 'selection', payload: { start, end } }) }} ref={textInputRef} scrollEnabled > {postState.text.formatted} ) } const styles = StyleSheet.create({ textInput: { 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 React.memo( ComposeTextInput, (prev, next) => prev.postState.text.formatted === next.postState.text.formatted )