Skip to content

Commit f1ca5ce

Browse files
sgnycknitt
authored andcommitted
Update TextInput event types using Event.syntheticEvent (#467)
1 parent b5b3e4a commit f1ca5ce

2 files changed

Lines changed: 84 additions & 18 deletions

File tree

‎reason-react-native/src/components/TextInput.md‎

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,40 @@ wip: true
77
```reason
88
include TextInputElement;
99
10-
type event('a) = {. "nativeEvent": 'a};
10+
type changeEvent =
11+
Event.syntheticEvent({
12+
.
13+
"eventCount": int,
14+
"target": int,
15+
"text": string,
16+
});
17+
18+
type textInputEvent =
19+
Event.syntheticEvent({
20+
.
21+
"eventCount": int,
22+
"previousText": string,
23+
"range": {
24+
.
25+
"start": int,
26+
"_end": int,
27+
},
28+
"target": int,
29+
"text": string,
30+
});
1131
1232
type editingEvent =
13-
event({
33+
Event.syntheticEvent({
1434
.
1535
"text": string,
1636
"eventCount": int,
1737
"target": int,
1838
});
1939
2040
type contentSizeChangeEvent =
21-
event({
41+
Event.syntheticEvent({
2242
.
43+
"target": int,
2344
"contentSize": {
2445
.
2546
"width": float,
@@ -28,7 +49,7 @@ type contentSizeChangeEvent =
2849
});
2950
3051
type scrollEvent =
31-
event({
52+
Event.syntheticEvent({
3253
.
3354
"contentOffset": {
3455
.
@@ -43,9 +64,20 @@ type selection = {
4364
"_end": int,
4465
};
4566
46-
type selectionEvent = event(selection);
67+
type selectionChangeEvent =
68+
Event.syntheticEvent({
69+
.
70+
"selection": selection,
71+
"target": int,
72+
});
4773
48-
type keyPressEvent = event({. "key": string});
74+
type keyPressEvent =
75+
Event.syntheticEvent({
76+
.
77+
"key": string,
78+
"target": Js.Nullable.t(int),
79+
"eventCount": Js.Nullable.t(int),
80+
});
4981
5082
module DataDetectorTypes = TextInput_DataDetectorTypes;
5183
@@ -129,16 +161,17 @@ external make:
129161
~maxLength: int=?,
130162
~multiline: bool=?,
131163
~numberOfLines: int=?,
132-
~onBlur: unit => unit=?,
133-
~onChange: editingEvent => unit=?,
164+
~onBlur: Event.targetEvent => unit=?,
165+
~onChange: changeEvent => unit=?,
134166
~onChangeText: string => unit=?,
135167
~onContentSizeChange: contentSizeChangeEvent => unit=?,
136168
~onEndEditing: editingEvent => unit=?,
137169
~onFocus: Event.targetEvent => unit=?,
138170
~onKeyPress: keyPressEvent => unit=?,
139171
~onScroll: scrollEvent => unit=?,
140-
~onSelectionChange: selectionEvent => unit=?,
172+
~onSelectionChange: selectionChangeEvent => unit=?,
141173
~onSubmitEditing: editingEvent => unit=?,
174+
~onTextInput: textInputEvent => unit=?,
142175
~placeholder: string=?,
143176
~placeholderTextColor: Color.t=?,
144177
~returnKeyLabel: string=?,

‎reason-react-native/src/components/TextInput.re‎

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
11
include TextInputElement;
22

3-
type event('a) = {. "nativeEvent": 'a};
3+
type changeEvent =
4+
Event.syntheticEvent({
5+
.
6+
"eventCount": int,
7+
"target": int,
8+
"text": string,
9+
});
10+
11+
type textInputEvent =
12+
Event.syntheticEvent({
13+
.
14+
"eventCount": int,
15+
"previousText": string,
16+
"range": {
17+
.
18+
"start": int,
19+
"_end": int,
20+
},
21+
"target": int,
22+
"text": string,
23+
});
424

525
type editingEvent =
6-
event({
26+
Event.syntheticEvent({
727
.
828
"text": string,
929
"eventCount": int,
1030
"target": int,
1131
});
1232

1333
type contentSizeChangeEvent =
14-
event({
34+
Event.syntheticEvent({
1535
.
36+
"target": int,
1637
"contentSize": {
1738
.
1839
"width": float,
@@ -21,7 +42,7 @@ type contentSizeChangeEvent =
2142
});
2243

2344
type scrollEvent =
24-
event({
45+
Event.syntheticEvent({
2546
.
2647
"contentOffset": {
2748
.
@@ -36,9 +57,20 @@ type selection = {
3657
"_end": int,
3758
};
3859

39-
type selectionEvent = event(selection);
60+
type selectionChangeEvent =
61+
Event.syntheticEvent({
62+
.
63+
"selection": selection,
64+
"target": int,
65+
});
4066

41-
type keyPressEvent = event({. "key": string});
67+
type keyPressEvent =
68+
Event.syntheticEvent({
69+
.
70+
"key": string,
71+
"target": Js.Nullable.t(int),
72+
"eventCount": Js.Nullable.t(int),
73+
});
4274

4375
module DataDetectorTypes = TextInput_DataDetectorTypes;
4476

@@ -122,16 +154,17 @@ external make:
122154
~maxLength: int=?,
123155
~multiline: bool=?,
124156
~numberOfLines: int=?,
125-
~onBlur: unit => unit=?,
126-
~onChange: editingEvent => unit=?,
157+
~onBlur: Event.targetEvent => unit=?,
158+
~onChange: changeEvent => unit=?,
127159
~onChangeText: string => unit=?,
128160
~onContentSizeChange: contentSizeChangeEvent => unit=?,
129161
~onEndEditing: editingEvent => unit=?,
130162
~onFocus: Event.targetEvent => unit=?,
131163
~onKeyPress: keyPressEvent => unit=?,
132164
~onScroll: scrollEvent => unit=?,
133-
~onSelectionChange: selectionEvent => unit=?,
165+
~onSelectionChange: selectionChangeEvent => unit=?,
134166
~onSubmitEditing: editingEvent => unit=?,
167+
~onTextInput: textInputEvent => unit=?,
135168
~placeholder: string=?,
136169
~placeholderTextColor: Color.t=?,
137170
~returnKeyLabel: string=?,

0 commit comments

Comments
 (0)