@@ -34,6 +34,8 @@ const warning = require('fbjs/lib/warning');
34
34
import type { TextStyleProp , ViewStyleProp } from 'StyleSheet' ;
35
35
import type { ColorValue } from 'StyleSheetTypes' ;
36
36
import type { ViewProps } from 'ViewPropTypes' ;
37
+ import type { SyntheticEvent } from 'CoreEventTypes' ;
38
+ import type { PressEvent } from 'CoreEventTypes' ;
37
39
38
40
let AndroidTextInput ;
39
41
let RCTMultilineTextInputView ;
@@ -55,11 +57,70 @@ const onlyMultiline = {
55
57
children : true ,
56
58
} ;
57
59
58
- type Event = Object ;
59
- type Selection = {
60
+ type Range = $ReadOnly < { |
61
+ start : number ,
62
+ end : number ,
63
+ | } > ;
64
+ type Selection = $ReadOnly < { |
60
65
start : number ,
61
66
end ?: number ,
62
- } ;
67
+ | } > ;
68
+ type ContentSize = $ReadOnly < { |
69
+ width : number ,
70
+ height : number ,
71
+ | } > ;
72
+ type ContentOffset = $ReadOnly < { |
73
+ x : number ,
74
+ y : number ,
75
+ | } > ;
76
+ type ChangeEvent = SyntheticEvent <
77
+ $ReadOnly < { |
78
+ target : number ,
79
+ eventCount : number ,
80
+ text : string ,
81
+ | } > ,
82
+ > ;
83
+ type TextInputEvent = SyntheticEvent <
84
+ $ReadOnly < { |
85
+ previousText : string ,
86
+ range : Range ,
87
+ target : number ,
88
+ text : string ,
89
+ | } > ,
90
+ > ;
91
+ type ContentSizeChangeEvent = SyntheticEvent <
92
+ $ReadOnly < { |
93
+ target : number ,
94
+ contentSize : ContentSize ,
95
+ | } > ,
96
+ > ;
97
+ type ScrollEvent = SyntheticEvent <
98
+ $ReadOnly < { |
99
+ target : number ,
100
+ contentOffset : ContentOffset ,
101
+ | } > ,
102
+ > ;
103
+ type TargetEvent = SyntheticEvent <
104
+ $ReadOnly < { |
105
+ target : number ,
106
+ | } > ,
107
+ > ;
108
+ type SelectionChangeEvent = SyntheticEvent <
109
+ $ReadOnly < { |
110
+ selection : Selection ,
111
+ | } > ,
112
+ > ;
113
+ type KeyPressEvent = SyntheticEvent <
114
+ $ReadOnly < { |
115
+ key : string ,
116
+ | } > ,
117
+ > ;
118
+ type EditingEvent = SyntheticEvent <
119
+ $ReadOnly < { |
120
+ text : string ,
121
+ target : number ,
122
+ | } > ,
123
+ > ;
63
124
64
125
const DataDetectorTypes = [
65
126
'phoneNumber' ,
@@ -184,17 +245,17 @@ type Props = $ReadOnly<{|
184
245
returnKeyType ?: ?ReturnKeyType ,
185
246
maxLength ?: ?number ,
186
247
multiline ?: ?boolean ,
187
- onBlur ?: ?Function ,
188
- onFocus ?: ?Function ,
189
- onChange ?: ?Function ,
190
- onChangeText ?: ?Function ,
191
- onContentSizeChange ?: ?Function ,
192
- onTextInput ?: ?Function ,
193
- onEndEditing ?: ?Function ,
194
- onSelectionChange ?: ?Function ,
195
- onSubmitEditing ?: ?Function ,
196
- onKeyPress ?: ?Function ,
197
- onScroll ?: ?Function ,
248
+ onBlur ?: ?( e : TargetEvent ) => void ,
249
+ onFocus ?: ?( e : TargetEvent ) => void ,
250
+ onChange ?: ?( e : ChangeEvent ) => void ,
251
+ onChangeText ?: ?( text : string ) => void ,
252
+ onContentSizeChange ?: ?( e : ContentSizeChangeEvent ) => void ,
253
+ onTextInput ?: ?( e : TextInputEvent ) => void ,
254
+ onEndEditing ?: ?( e : EditingEvent ) => void ,
255
+ onSelectionChange ?: ?( e : SelectionChangeEvent ) => void ,
256
+ onSubmitEditing ?: ?( e : EditingEvent ) => void ,
257
+ onKeyPress ?: ?( e : KeyPressEvent ) => void ,
258
+ onScroll ?: ?( e : ScrollEvent ) => void ,
198
259
placeholder ?: ?Stringish ,
199
260
placeholderTextColor ?: ?ColorValue ,
200
261
secureTextEntry ?: ?boolean ,
@@ -792,7 +853,7 @@ const TextInput = createReactClass({
792
853
'oneTimeCode' ,
793
854
] ) ,
794
855
} ,
795
- getDefaultProps ( ) : Object {
856
+ getDefaultProps ( ) {
796
857
return {
797
858
allowFontScaling : true ,
798
859
underlineColorAndroid : 'transparent' ,
@@ -1108,7 +1169,7 @@ const TextInput = createReactClass({
1108
1169
) ;
1109
1170
} ,
1110
1171
1111
- _onFocus : function ( event : Event ) {
1172
+ _onFocus : function ( event : TargetEvent ) {
1112
1173
if ( this . props . onFocus ) {
1113
1174
this . props . onFocus ( event ) ;
1114
1175
}
@@ -1118,13 +1179,13 @@ const TextInput = createReactClass({
1118
1179
}
1119
1180
} ,
1120
1181
1121
- _onPress : function ( event : Event ) {
1182
+ _onPress : function ( event : PressEvent ) {
1122
1183
if ( this . props . editable || this . props . editable === undefined ) {
1123
1184
this . focus ( ) ;
1124
1185
}
1125
1186
} ,
1126
1187
1127
- _onChange : function ( event : Event ) {
1188
+ _onChange : function ( event : ChangeEvent ) {
1128
1189
// Make sure to fire the mostRecentEventCount first so it is already set on
1129
1190
// native when the text value is set.
1130
1191
if ( this . _inputRef && this . _inputRef . setNativeProps ) {
@@ -1147,7 +1208,7 @@ const TextInput = createReactClass({
1147
1208
this . forceUpdate ( ) ;
1148
1209
} ,
1149
1210
1150
- _onSelectionChange : function ( event : Event ) {
1211
+ _onSelectionChange : function ( event : SelectionChangeEvent ) {
1151
1212
this . props . onSelectionChange && this . props . onSelectionChange ( event ) ;
1152
1213
1153
1214
if ( ! this . _inputRef ) {
@@ -1201,7 +1262,7 @@ const TextInput = createReactClass({
1201
1262
}
1202
1263
} ,
1203
1264
1204
- _onBlur : function ( event : Event ) {
1265
+ _onBlur : function ( event : TargetEvent ) {
1205
1266
if ( this . props . onBlur ) {
1206
1267
this . props . onBlur ( event ) ;
1207
1268
}
@@ -1211,11 +1272,11 @@ const TextInput = createReactClass({
1211
1272
}
1212
1273
} ,
1213
1274
1214
- _onTextInput : function ( event : Event ) {
1275
+ _onTextInput : function ( event : TextInputEvent ) {
1215
1276
this . props . onTextInput && this . props . onTextInput ( event ) ;
1216
1277
} ,
1217
1278
1218
- _onScroll : function ( event : Event ) {
1279
+ _onScroll : function ( event : ScrollEvent ) {
1219
1280
this . props . onScroll && this . props . onScroll ( event ) ;
1220
1281
} ,
1221
1282
} ) ;
0 commit comments