@@ -17,12 +17,13 @@ const StyleSheet = require('../../StyleSheet/StyleSheet');
17
17
const Text = require ( '../../Text/Text' ) ;
18
18
const TextAncestor = require ( '../../Text/TextAncestor' ) ;
19
19
const TextInputState = require ( './TextInputState' ) ;
20
- const TouchableWithoutFeedback = require ( '../Touchable/TouchableWithoutFeedback' ) ;
21
20
22
21
const invariant = require ( 'invariant' ) ;
23
22
const nullthrows = require ( 'nullthrows' ) ;
24
23
const setAndForwardRef = require ( '../../Utilities/setAndForwardRef' ) ;
25
24
25
+ import usePressability from '../../Pressability/usePressability' ;
26
+
26
27
import type { TextStyleProp , ViewStyleProp } from '../../StyleSheet/StyleSheet' ;
27
28
import type { ColorValue } from '../../StyleSheet/StyleSheet' ;
28
29
import type { ViewProps } from '../View/ViewPropTypes' ;
@@ -1002,12 +1003,6 @@ function InternalTextInput(props: Props): React.Node {
1002
1003
} ,
1003
1004
} ) ;
1004
1005
1005
- const _onPress = ( event : PressEvent ) => {
1006
- if ( props . editable || props . editable === undefined ) {
1007
- nullthrows ( inputRef . current ) . focus ( ) ;
1008
- }
1009
- } ;
1010
-
1011
1006
const _onChange = ( event : ChangeEvent ) => {
1012
1007
const text = event . nativeEvent . text ;
1013
1008
props . onChange && props . onChange ( event ) ;
@@ -1061,18 +1056,38 @@ function InternalTextInput(props: Props): React.Node {
1061
1056
} ;
1062
1057
1063
1058
let textInput = null ;
1064
- let additionalTouchableProps : { |
1065
- rejectResponderTermination ? : $PropertyType <
1066
- Props ,
1067
- 'rejectResponderTermination' ,
1068
- > ,
1069
- // This is a hack to let Flow know we want an exact object
1070
- | } = { ...null } ;
1071
1059
1072
1060
// The default value for `blurOnSubmit` is true for single-line fields and
1073
1061
// false for multi-line fields.
1074
1062
const blurOnSubmit = props . blurOnSubmit ?? ! props . multiline ;
1075
1063
1064
+ const accessible = props . accessible !== false ;
1065
+ const focusable = props . focusable !== false ;
1066
+
1067
+ const config = React . useMemo (
1068
+ ( ) => ( {
1069
+ onPress : ( event : PressEvent ) => {
1070
+ if ( props . editable !== false ) {
1071
+ nullthrows ( inputRef . current ) . focus ( ) ;
1072
+ }
1073
+ } ,
1074
+ onPressIn : props . onPressIn ,
1075
+ onPressOut : props . onPressOut ,
1076
+ cancelable :
1077
+ Platform . OS === 'ios' ? ! props . rejectResponderTermination : null ,
1078
+ } ) ,
1079
+ [
1080
+ props . editable ,
1081
+ props . onPressIn ,
1082
+ props . onPressOut ,
1083
+ props . rejectResponderTermination ,
1084
+ ] ,
1085
+ ) ;
1086
+
1087
+ // TextInput handles onBlur and onFocus events
1088
+ // so omitting onBlur and onFocus pressability handlers here.
1089
+ const { onBlur, onFocus, ...eventHandlers } = usePressability ( config ) || { } ;
1090
+
1076
1091
if ( Platform . OS === 'ios' ) {
1077
1092
const RCTTextInputView = props . multiline
1078
1093
? RCTMultilineTextInputView
@@ -1082,15 +1097,15 @@ function InternalTextInput(props: Props): React.Node {
1082
1097
? [ styles . multilineInput , props . style ]
1083
1098
: props . style ;
1084
1099
1085
- additionalTouchableProps . rejectResponderTermination =
1086
- props . rejectResponderTermination ;
1087
-
1088
1100
textInput = (
1089
1101
< RCTTextInputView
1090
1102
ref = { _setNativeRef }
1091
1103
{ ...props }
1104
+ { ...eventHandlers }
1105
+ accessible = { accessible }
1092
1106
blurOnSubmit = { blurOnSubmit }
1093
1107
dataDetectorTypes = { props . dataDetectorTypes }
1108
+ focusable = { focusable }
1094
1109
mostRecentEventCount = { mostRecentEventCount }
1095
1110
onBlur = { _onBlur }
1096
1111
onChange = { _onChange }
@@ -1123,10 +1138,13 @@ function InternalTextInput(props: Props): React.Node {
1123
1138
< AndroidTextInput
1124
1139
ref = { _setNativeRef }
1125
1140
{ ...props }
1141
+ { ...eventHandlers }
1142
+ accessible = { accessible }
1126
1143
autoCapitalize = { autoCapitalize }
1127
1144
blurOnSubmit = { blurOnSubmit }
1128
1145
children = { children }
1129
1146
disableFullscreenUI = { props . disableFullscreenUI }
1147
+ focusable = { focusable }
1130
1148
mostRecentEventCount = { mostRecentEventCount }
1131
1149
onBlur = { _onBlur }
1132
1150
onChange = { _onChange }
@@ -1143,22 +1161,7 @@ function InternalTextInput(props: Props): React.Node {
1143
1161
) ;
1144
1162
}
1145
1163
return (
1146
- < TextAncestor . Provider value = { true } >
1147
- < TouchableWithoutFeedback
1148
- onLayout = { props . onLayout }
1149
- onPress = { _onPress }
1150
- onPressIn = { props . onPressIn }
1151
- onPressOut = { props . onPressOut }
1152
- accessible = { props . accessible }
1153
- accessibilityLabel = { props . accessibilityLabel }
1154
- accessibilityRole = { props . accessibilityRole }
1155
- accessibilityState = { props . accessibilityState }
1156
- nativeID = { props . nativeID }
1157
- testID = { props . testID }
1158
- { ...additionalTouchableProps } >
1159
- { textInput }
1160
- </ TouchableWithoutFeedback >
1161
- </ TextAncestor . Provider >
1164
+ < TextAncestor . Provider value = { true } > { textInput } </ TextAncestor . Provider >
1162
1165
) ;
1163
1166
}
1164
1167
0 commit comments