Skip to content

Commit fff55d6

Browse files
sgnyMoOx
authored andcommitted
Add documentation for Event API (#515)
1 parent 1e6afe8 commit fff55d6

1 file changed

Lines changed: 80 additions & 30 deletions

File tree

‎reason-react-native/src/apis/Event.md‎

Lines changed: 80 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
---
22
id: apis/Event
33
title: Event
4-
wip: true
4+
officialDoc: https://github.com/facebook/react-native/blob/master/Libraries/Types/CoreEventTypes.js
55
---
66

7-
```reason
8-
// see https://github.com/facebook/react-native/blob/master/Libraries/Types/CoreEventTypes.js
7+
These are the types of objects returned in `Event` callbacks. Types are
8+
instances of `syntheticEvent('a)` and `responderSyntheticEvent('a)`.
9+
10+
## Parametrised Types
11+
12+
### `syntheticEvent('a)`
913

14+
```reason
1015
type syntheticEvent('a) = {
1116
.
1217
"bubbles": Js.Nullable.t(bool),
@@ -26,7 +31,13 @@ type syntheticEvent('a) = {
2631
"timeStamp": float,
2732
"_type": Js.Nullable.t(string),
2833
};
34+
```
35+
36+
### `responderSyntheticEvent('a)`
2937

38+
`responderSyntheticEvent('a)` adds the `touchHistory` key to `syntheticEvent('a)`
39+
40+
```reason
3041
type responderSyntheticEvent('a) = {
3142
.
3243
// synthethicEvent keys
@@ -46,7 +57,6 @@ type responderSyntheticEvent('a) = {
4657
"target": Js.Nullable.t(float),
4758
"timeStamp": float,
4859
"_type": Js.Nullable.t(string),
49-
// responderSyntheticEvent additional key
5060
"touchHistory": {
5161
.
5262
"indexOfSingleActiveTouch": float,
@@ -68,20 +78,13 @@ type responderSyntheticEvent('a) = {
6878
}),
6979
},
7080
};
81+
```
7182

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-
};
83+
## Types
8484

85+
### `layoutEvent`
86+
87+
```reason
8588
type layoutEvent =
8689
syntheticEvent({
8790
.
@@ -93,9 +96,17 @@ type layoutEvent =
9396
"height": float,
9497
},
9598
});
99+
```
96100

97-
type textLayoutEvent = syntheticEvent({. "lines": array(textLayout)});
101+
### `pressEvent`
102+
103+
```reason
104+
type pressEvent = responderSyntheticEvent(pressEventPayload);
105+
```
98106

107+
where `pressEventPayload` is defined as
108+
109+
```reason
99110
type pressEventPayload = {
100111
.
101112
"changedTouches": array(pressEventPayload),
@@ -109,21 +120,11 @@ type pressEventPayload = {
109120
"timestamp": float,
110121
"touches": array(pressEventPayload),
111122
};
123+
```
112124

113-
type pressEvent = responderSyntheticEvent(pressEventPayload);
114-
115-
type contentOffset = {
116-
.
117-
"x": float,
118-
"y": float,
119-
};
120-
121-
type dimensions = {
122-
.
123-
"height": float,
124-
"width": float,
125-
};
125+
### `scrollEvent`
126126

127+
```reason
127128
type scrollEvent =
128129
syntheticEvent({
129130
.
@@ -138,9 +139,58 @@ type scrollEvent =
138139
"contentSize": dimensions,
139140
"layoutMeasurement": dimensions,
140141
});
142+
```
143+
144+
where `contentOffset` and `dimensions` are defined as
145+
146+
```reason
147+
type contentOffset = {
148+
.
149+
"x": float,
150+
"y": float,
151+
};
152+
```
141153

154+
```reason
155+
type dimensions = {
156+
.
157+
"height": float,
158+
"width": float,
159+
};
160+
```
161+
162+
### `switchChangeEvent`
163+
164+
```reason
142165
type switchChangeEvent = syntheticEvent({. "value": bool});
166+
```
167+
168+
### `targetEvent`
143169

170+
```reason
144171
type targetEvent = syntheticEvent({. "target": int});
145172
146173
```
174+
175+
### `textLayoutEvent`
176+
177+
```reason
178+
type textLayoutEvent = syntheticEvent({. "lines": array(textLayout)});
179+
```
180+
181+
where `textLayout` is defined as
182+
183+
```reason
184+
type textLayout = {
185+
.
186+
"x": float,
187+
"y": float,
188+
"width": float,
189+
"height": float,
190+
"ascender": float, // verify
191+
"capHeight": float, // verify
192+
"descender": float, // verify
193+
"text": string,
194+
"xHeight": float // verify
195+
};
196+
```

0 commit comments

Comments
 (0)