Skip to content

Commit e9911dd

Browse files
sgnycknitt
authored andcommitted
Complete implementation of CoreEventTypes (#412)
* Complete implementation of CoreEventTypes * Add comments * Revise comment
1 parent d688e7e commit e9911dd

4 files changed

Lines changed: 186 additions & 32 deletions

File tree

‎bs-react-native-next/src/apis/Event.md‎

Lines changed: 91 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,94 @@ wip: true
77
```reason
88
// see https://github.com/facebook/react-native/blob/master/Libraries/Types/CoreEventTypes.js
99
10-
type event('a) = {. "nativeEvent": 'a};
10+
type syntheticEvent('a) = {
11+
.
12+
"bubbles": Js.Nullable.t(bool),
13+
"cancelable": Js.Nullable.t(bool),
14+
"currentTarget": float,
15+
"defaultPrevented": Js.Nullable.t(bool),
16+
"dispatchConfig": {. "registrationName": string},
17+
"eventPhase": Js.Nullable.t(float),
18+
"preventDefault": unit => unit,
19+
"isDefaultPrevented": unit => bool,
20+
"stopPropagation": unit => unit,
21+
"isPropagationStopped": unit => bool,
22+
"isTrusted": Js.Nullable.t(bool),
23+
"nativeEvent": 'a,
24+
"persist": unit => unit,
25+
"target": Js.Nullable.t(float),
26+
"timeStamp": float,
27+
"_type": Js.Nullable.t(string),
28+
};
29+
30+
type responderSyntheticEvent('a) = {
31+
.
32+
// synthethicEvent keys
33+
"bubbles": Js.Nullable.t(bool),
34+
"cancelable": Js.Nullable.t(bool),
35+
"currentTarget": float,
36+
"defaultPrevented": Js.Nullable.t(bool),
37+
"dispatchConfig": {. "registrationName": string},
38+
"eventPhase": Js.Nullable.t(float),
39+
"preventDefault": unit => unit,
40+
"isDefaultPrevented": unit => bool,
41+
"stopPropagation": unit => unit,
42+
"isPropagationStopped": unit => bool,
43+
"isTrusted": Js.Nullable.t(bool),
44+
"nativeEvent": 'a,
45+
"persist": unit => unit,
46+
"target": Js.Nullable.t(float),
47+
"timeStamp": float,
48+
"_type": Js.Nullable.t(string),
49+
// responderSyntheticEvent additional key
50+
"touchHistory": {
51+
.
52+
"indexOfSingleActiveTouch": float,
53+
"mostRecentTimeStamp": float,
54+
"numberActiveTouches": float,
55+
"touchBank":
56+
array({
57+
.
58+
"touchActive": bool,
59+
"startPageX": float,
60+
"startPageY": float,
61+
"startTimeStamp": float,
62+
"currentPageX": float,
63+
"currentPageY": float,
64+
"currentTimeStamp": float,
65+
"previousPageX": float,
66+
"previousPageY": float,
67+
"previousTimeStamp": float,
68+
}),
69+
},
70+
};
71+
72+
type textLayout = {
73+
.
74+
"x": float,
75+
"y": float,
76+
"width": float,
77+
"height": float,
78+
"ascender": float, // verify
79+
"capHeight": float, // verify
80+
"descender": float, // verify
81+
"text": string,
82+
"xHeight": float // verify
83+
};
84+
85+
type layoutEvent =
86+
syntheticEvent({
87+
.
88+
"layout": {
89+
.
90+
"x": float,
91+
"y": float,
92+
"width": float,
93+
"height": float,
94+
},
95+
});
96+
97+
type textLayoutEvent = syntheticEvent({. "lines": array(textLayout)});
1198
1299
type pressEventPayload = {
13100
.
@@ -23,7 +110,7 @@ type pressEventPayload = {
23110
"touches": array(pressEventPayload),
24111
};
25112
26-
type pressEvent = event(pressEventPayload);
113+
type pressEvent = responderSyntheticEvent(pressEventPayload);
27114
28115
type position = {
29116
.
@@ -38,7 +125,7 @@ type dimensions = {
38125
};
39126
40127
type scrollEvent =
41-
event({
128+
syntheticEvent({
42129
.
43130
"contentInset": {
44131
.
@@ -52,16 +139,6 @@ type scrollEvent =
52139
"layoutMeasurement": dimensions,
53140
});
54141
55-
type layoutEvent =
56-
event({
57-
.
58-
"layout": {
59-
.
60-
"x": float,
61-
"y": float,
62-
"width": float,
63-
"height": float,
64-
},
65-
});
142+
type switchChangeEvent = syntheticEvent({. "value": bool});
66143
67144
```

‎bs-react-native-next/src/apis/Event.re‎

Lines changed: 91 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,93 @@
11
// see https://github.com/facebook/react-native/blob/master/Libraries/Types/CoreEventTypes.js
22

3-
type event('a) = {. "nativeEvent": 'a};
3+
type syntheticEvent('a) = {
4+
.
5+
"bubbles": Js.Nullable.t(bool),
6+
"cancelable": Js.Nullable.t(bool),
7+
"currentTarget": float,
8+
"defaultPrevented": Js.Nullable.t(bool),
9+
"dispatchConfig": {. "registrationName": string},
10+
"eventPhase": Js.Nullable.t(float),
11+
"preventDefault": unit => unit,
12+
"isDefaultPrevented": unit => bool,
13+
"stopPropagation": unit => unit,
14+
"isPropagationStopped": unit => bool,
15+
"isTrusted": Js.Nullable.t(bool),
16+
"nativeEvent": 'a,
17+
"persist": unit => unit,
18+
"target": Js.Nullable.t(float),
19+
"timeStamp": float,
20+
"_type": Js.Nullable.t(string),
21+
};
22+
23+
type responderSyntheticEvent('a) = {
24+
.
25+
// synthethicEvent keys
26+
"bubbles": Js.Nullable.t(bool),
27+
"cancelable": Js.Nullable.t(bool),
28+
"currentTarget": float,
29+
"defaultPrevented": Js.Nullable.t(bool),
30+
"dispatchConfig": {. "registrationName": string},
31+
"eventPhase": Js.Nullable.t(float),
32+
"preventDefault": unit => unit,
33+
"isDefaultPrevented": unit => bool,
34+
"stopPropagation": unit => unit,
35+
"isPropagationStopped": unit => bool,
36+
"isTrusted": Js.Nullable.t(bool),
37+
"nativeEvent": 'a,
38+
"persist": unit => unit,
39+
"target": Js.Nullable.t(float),
40+
"timeStamp": float,
41+
"_type": Js.Nullable.t(string),
42+
// responderSyntheticEvent additional key
43+
"touchHistory": {
44+
.
45+
"indexOfSingleActiveTouch": float,
46+
"mostRecentTimeStamp": float,
47+
"numberActiveTouches": float,
48+
"touchBank":
49+
array({
50+
.
51+
"touchActive": bool,
52+
"startPageX": float,
53+
"startPageY": float,
54+
"startTimeStamp": float,
55+
"currentPageX": float,
56+
"currentPageY": float,
57+
"currentTimeStamp": float,
58+
"previousPageX": float,
59+
"previousPageY": float,
60+
"previousTimeStamp": float,
61+
}),
62+
},
63+
};
64+
65+
type textLayout = {
66+
.
67+
"x": float,
68+
"y": float,
69+
"width": float,
70+
"height": float,
71+
"ascender": float, // verify
72+
"capHeight": float, // verify
73+
"descender": float, // verify
74+
"text": string,
75+
"xHeight": float // verify
76+
};
77+
78+
type layoutEvent =
79+
syntheticEvent({
80+
.
81+
"layout": {
82+
.
83+
"x": float,
84+
"y": float,
85+
"width": float,
86+
"height": float,
87+
},
88+
});
89+
90+
type textLayoutEvent = syntheticEvent({. "lines": array(textLayout)});
491

592
type pressEventPayload = {
693
.
@@ -16,7 +103,7 @@ type pressEventPayload = {
16103
"touches": array(pressEventPayload),
17104
};
18105

19-
type pressEvent = event(pressEventPayload);
106+
type pressEvent = responderSyntheticEvent(pressEventPayload);
20107

21108
type position = {
22109
.
@@ -31,7 +118,7 @@ type dimensions = {
31118
};
32119

33120
type scrollEvent =
34-
event({
121+
syntheticEvent({
35122
.
36123
"contentInset": {
37124
.
@@ -45,14 +132,4 @@ type scrollEvent =
45132
"layoutMeasurement": dimensions,
46133
});
47134

48-
type layoutEvent =
49-
event({
50-
.
51-
"layout": {
52-
.
53-
"x": float,
54-
"y": float,
55-
"width": float,
56-
"height": float,
57-
},
58-
});
135+
type switchChangeEvent = syntheticEvent({. "value": bool});

‎bs-react-native-next/src/components/WebView.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ module Source = {
3030
module DataDetectorTypes = WebView_DataDetectorTypes;
3131
module DecelerationRate = WebView_DecelerationRate;
3232
33-
type messageEvent = Event.event({. "data": string});
33+
type messageEvent = Event.syntheticEvent({. "data": string});
3434
3535
type webViewEvent =
36-
Event.event({
36+
Event.syntheticEvent({
3737
.
3838
"url": string,
3939
"title": string,

‎bs-react-native-next/src/components/WebView.re‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ module Source = {
2323
module DataDetectorTypes = WebView_DataDetectorTypes;
2424
module DecelerationRate = WebView_DecelerationRate;
2525

26-
type messageEvent = Event.event({. "data": string});
26+
type messageEvent = Event.syntheticEvent({. "data": string});
2727

2828
type webViewEvent =
29-
Event.event({
29+
Event.syntheticEvent({
3030
.
3131
"url": string,
3232
"title": string,

0 commit comments

Comments
 (0)