@@ -20,7 +20,6 @@ import type {
2020import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes' ;
2121import type { TextInputInstance , TextInputType } from 'react-native/Libraries/Components/TextInput/TextInput.flow' ;
2222
23- import * as ReactNativeFeatureFlags from 'react-native/src/private/featureflags/ReactNativeFeatureFlags.js' ;
2423import usePressability from 'react-native/Libraries/Pressability/usePressability.js' ;
2524import flattenStyle from 'react-native/Libraries/StyleSheet/flattenStyle.js' ;
2625import StyleSheet , {
@@ -1010,7 +1009,7 @@ const emptyFunctionThatReturnsTrue = () => true;
10101009 * in native and in JavaScript. This is necessary due to the asynchronous nature
10111010 * of text input events.
10121011 */
1013- function useTextInputStateSynchronization_STATE ( {
1012+ function useTextInputStateSynchronization ( {
10141013 props,
10151014 mostRecentEventCount,
10161015 selection,
@@ -1086,94 +1085,6 @@ function useTextInputStateSynchronization_STATE({
10861085 return { setLastNativeText , setLastNativeSelection} ;
10871086}
10881087
1089- /**
1090- * This hook handles the synchronization between the state of the text input
1091- * in native and in JavaScript. This is necessary due to the asynchronous nature
1092- * of text input events.
1093- */
1094- function useTextInputStateSynchronization_REFS ( {
1095- props ,
1096- mostRecentEventCount ,
1097- selection ,
1098- inputRef ,
1099- text ,
1100- viewCommands ,
1101- } : {
1102- props : TextInputProps ,
1103- mostRecentEventCount : number ,
1104- selection : ?Selection ,
1105- inputRef : React . RefObject < null | TextInputInstance > ,
1106- text ? : string ,
1107- viewCommands : ViewCommands ,
1108- } ) : {
1109- setLastNativeText : string => void ,
1110- setLastNativeSelection : LastNativeSelection => void ,
1111- } {
1112- const lastNativeTextRef = useRef < ?Stringish > ( props . value ) ;
1113- const lastNativeSelectionRef = useRef < LastNativeSelection > ( {
1114- selection : { start : - 1 , end : - 1 } ,
1115- mostRecentEventCount : mostRecentEventCount ,
1116- } ) ;
1117-
1118- // This is necessary in case native updates the text and JS decides
1119- // that the update should be ignored and we should stick with the value
1120- // that we have in JS.
1121- useLayoutEffect ( ( ) => {
1122- const nativeUpdate : { text ?: string , selection ?: Selection } = { } ;
1123-
1124- const lastNativeSelection = lastNativeSelectionRef . current . selection ;
1125-
1126- if (
1127- lastNativeTextRef . current !== props . value &&
1128- typeof props . value === 'string'
1129- ) {
1130- nativeUpdate . text = props . value ;
1131- lastNativeTextRef . current = props . value ;
1132- }
1133-
1134- if (
1135- selection &&
1136- lastNativeSelection &&
1137- ( lastNativeSelection . start !== selection . start ||
1138- lastNativeSelection . end !== selection . end )
1139- ) {
1140- nativeUpdate . selection = selection ;
1141- lastNativeSelectionRef . current = { selection, mostRecentEventCount} ;
1142- }
1143-
1144- if ( Object . keys ( nativeUpdate ) . length === 0 ) {
1145- return ;
1146- }
1147-
1148- if ( inputRef . current != null ) {
1149- viewCommands . setTextAndSelection (
1150- inputRef . current ,
1151- mostRecentEventCount ,
1152- text ,
1153- selection ?. start ?? - 1 ,
1154- selection ?. end ?? - 1 ,
1155- ) ;
1156- }
1157- } , [
1158- mostRecentEventCount ,
1159- inputRef ,
1160- props . value ,
1161- props . defaultValue ,
1162- selection ,
1163- text ,
1164- viewCommands ,
1165- ] ) ;
1166-
1167- return {
1168- setLastNativeText : lastNativeText => {
1169- lastNativeTextRef . current = lastNativeText ;
1170- } ,
1171- setLastNativeSelection : lastNativeSelection => {
1172- lastNativeSelectionRef . current = lastNativeSelection ;
1173- } ,
1174- } ;
1175- }
1176-
11771088/**
11781089 * A foundational component for inputting text into the app via a
11791090 * keyboard. Props provide configurability for several features, such as
@@ -1326,10 +1237,6 @@ function InternalTextInput(props: TextInputProps): React.Node {
13261237 : RCTSinglelineTextInputNativeCommands ) ;
13271238
13281239 const [ mostRecentEventCount , setMostRecentEventCount ] = useState < number > ( 0 ) ;
1329- const useTextInputStateSynchronization =
1330- ReactNativeFeatureFlags . useRefsForTextInputState ( )
1331- ? useTextInputStateSynchronization_REFS
1332- : useTextInputStateSynchronization_STATE ;
13331240 const { setLastNativeText, setLastNativeSelection} =
13341241 useTextInputStateSynchronization ( {
13351242 props,
0 commit comments