You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contributing/event-dispatch.md
+16-2Lines changed: 16 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,23 @@
2
2
3
3
RNTL has two ways to trigger events. Neither goes through React Native's native event system. Both find `on*` props in the rendered tree and call them inside `act()`.
4
4
5
+
Both are built on the shared event subsystem in `src/events/`, which also holds `fireEvent` itself:
|`handler.ts`| Finding the `on*` handler for an event name in props |
11
+
|`propagation.ts`| Bubbling vs direct events, walking up host and composite elements |
12
+
|`is-enabled.ts`| Whether a device would deliver the event: `pointerEvents`, `editable`, touch responders |
13
+
|`dispatch.ts`|`dispatchEvent()`: calls the target's own handler in `act()`, used by `userEvent`|
14
+
|`builders/`| Event payloads, matching what React Native sends on a device |
15
+
|`native-state.ts`, `update-native-state.ts`|[Native state](native-state.md) and how `fireEvent` updates it |
16
+
17
+
`src/user-event/` is a separate module on top of `src/events/` and imports it only through `src/events/index.ts`.
18
+
5
19
## `fireEvent`
6
20
7
-
`src/fire-event.ts` calls a single handler for a single event. The work is in finding the right handler:
21
+
`src/events/fire-event.ts`is the public API. It calls a single handler for a single event, found with `findEventHandler()` from `src/events/propagation.ts`. The work is in finding the right handler:
8
22
9
23
- It starts at the target and moves up the tree until it finds a handler. It also checks props of composite components, not only host elements.
10
24
- Direct events (see [Native event propagation](native-events.md)) only check the target.
@@ -20,5 +34,5 @@ Each step uses `dispatchEvent()`, which only calls the target's own handler. It
20
34
21
35
- To change which handler gets a single event, change `fireEvent`. To make an interaction more realistic, change the `userEvent` action.
22
36
- Keep `dispatchEvent()` simple.
23
-
- Put rules that both need, like `pointerEvents`or`editable`, in shared helpers in`src/helpers/`.
37
+
- Put event rules that both need, like the `pointerEvents`and`editable` checks, in `src/events/`. They may build on general helpers from`src/helpers/` (for example `isEditableTextInput`). Code used only by `userEvent`, like delays and scroll steps, stays in `src/user-event/`.
24
38
- Event sequences should match a real device. Check on a device before changing one, and keep the code comments explaining the observed behavior.
Copy file name to clipboardExpand all lines: contributing/native-events.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
In React Native, some events **bubble** up to parent elements and others are **direct**, meaning only the element that emitted them receives them. `fireEvent` should behave the same way.
4
4
5
-
Today, `fireEvent` treats every event as bubbling except `layout`. The list of direct events lives in `isDirectEvent()` in `src/fire-event.ts`.
5
+
Today, `fireEvent` treats every event as bubbling except `layout`. The list of direct events lives in `isDirectEvent()` in `src/events/propagation.ts`.
Copy file name to clipboardExpand all lines: contributing/native-state.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Native State
2
2
3
-
On a device, some component state lives in native views, not in React. Jest has no native views, so RNTL keeps this state itself in `src/native-state.ts`.
3
+
On a device, some component state lives in native views, not in React. Jest has no native views, so RNTL keeps this state itself in `src/events/native-state.ts`.
4
4
5
5
## What is stored
6
6
@@ -10,7 +10,7 @@ On a device, some component state lives in native views, not in React. Jest has
10
10
11
11
## Key points
12
12
13
-
-**Writes.**`fireEvent` and `userEvent` update native state when they simulate a change that a native view would make.
13
+
-**Writes.**`fireEvent` and `userEvent` update native state when they simulate a change that a native view would make.`fireEvent` does it through `updateNativeStateFromEvent()` in `src/events/update-native-state.ts`. Each `userEvent` action writes it directly.
14
14
-**Reads.** Helpers read native state, like `getTextInputValue()` in `src/helpers/text-input.ts`. Queries and matchers use those helpers instead of reading native state directly.
15
15
-**Props win.** A controlled prop (like `value`) always takes precedence over native state.
16
16
-**No reset.** State is stored in `WeakMap`s keyed by host instance. It disappears when the instance is unmounted, so `cleanup()` doesn't need to clear it.
0 commit comments