1- import React , { useCallback , useEffect , useMemo , useState } from 'react' ;
1+ import React , { useCallback , useMemo , useState } from 'react' ;
22import {
33 I18nManager ,
44 NativeSyntheticEvent ,
@@ -23,17 +23,6 @@ import {
2323
2424import { useStateStore } from '../../hooks/useStateStore' ;
2525
26- const styles = StyleSheet . create ( {
27- inputBox : {
28- flex : 1 ,
29- fontSize : 16 ,
30- includeFontPadding : false , // for android vertical text centering
31- padding : 0 , // removal of default text input padding on android
32- paddingTop : 0 , // removal of iOS top padding for weird centering
33- textAlignVertical : 'center' , // for android vertical text centering
34- } ,
35- } ) ;
36-
3726type AutoCompleteInputPropsWithContext = Pick <
3827 MessageInputContextValue ,
3928 | 'additionalTextInputProps'
@@ -56,6 +45,7 @@ type AutoCompleteInputPropsWithContext = Pick<
5645export type AutoCompleteInputProps = Partial < AutoCompleteInputPropsWithContext > ;
5746
5847const messageComposerStateSelector = ( state : TextComposerState ) => ( {
48+ selection : state . selection ,
5949 text : state . text ,
6050} ) ;
6151
@@ -72,18 +62,13 @@ const AutoCompleteInputWithContext = (props: AutoCompleteInputPropsWithContext)
7262 setInputBoxRef,
7363 t,
7464 } = props ;
75- const [ localText , setLocalText ] = useState ( '' ) ;
7665 const [ selection , setSelection ] = useState ( { end : 0 , start : 0 } ) ;
7766 const [ textHeight , setTextHeight ] = useState ( 0 ) ;
7867 const messageComposer = useMessageComposer ( ) ;
7968 const { textComposer } = messageComposer ;
8069
8170 const { text } = useStateStore ( textComposer . state , messageComposerStateSelector ) ;
8271
83- useEffect ( ( ) => {
84- setLocalText ( text ) ;
85- } , [ text ] ) ;
86-
8772 const handleSelectionChange = useCallback (
8873 ( e : NativeSyntheticEvent < TextInputSelectionChangeEventData > ) => {
8974 const { selection } = e . nativeEvent ;
@@ -106,7 +91,6 @@ const AutoCompleteInputWithContext = (props: AutoCompleteInputPropsWithContext)
10691 additionalTextInputProps . onChangeText ( newText ) ;
10792 return ;
10893 }
109- setLocalText ( newText ) ;
11094 const isGiphy = giphyEnabled && newText && newText . startsWith ( '/giphy ' ) ;
11195
11296 if ( isGiphy ) {
@@ -121,15 +105,7 @@ const AutoCompleteInputWithContext = (props: AutoCompleteInputPropsWithContext)
121105 text : isGiphy ? newText . slice ( 7 ) : newText ,
122106 } ) ;
123107 } ,
124- [
125- additionalTextInputProps ,
126- giphyEnabled ,
127- onChangeText ,
128- textComposer ,
129- selection . end ,
130- selection . start ,
131- setGiphyActive ,
132- ] ,
108+ [ additionalTextInputProps , giphyEnabled , onChangeText , textComposer , selection , setGiphyActive ] ,
133109 ) ;
134110
135111 const {
@@ -177,7 +153,7 @@ const AutoCompleteInputWithContext = (props: AutoCompleteInputPropsWithContext)
177153 inputBox ,
178154 ] }
179155 testID = 'auto-complete-text-input'
180- value = { localText }
156+ value = { text }
181157 { ...additionalTextInputProps }
182158 />
183159 ) ;
@@ -244,4 +220,15 @@ export const AutoCompleteInput = (props: AutoCompleteInputProps) => {
244220 ) ;
245221} ;
246222
223+ const styles = StyleSheet . create ( {
224+ inputBox : {
225+ flex : 1 ,
226+ fontSize : 16 ,
227+ includeFontPadding : false , // for android vertical text centering
228+ padding : 0 , // removal of default text input padding on android
229+ paddingTop : 0 , // removal of iOS top padding for weird centering
230+ textAlignVertical : 'center' , // for android vertical text centering
231+ } ,
232+ } ) ;
233+
247234AutoCompleteInput . displayName = 'AutoCompleteInput{messageInput{inputBox}}' ;
0 commit comments