Commit 4fc7fac
Add selection to TextInput onChange event (native)
Summary:
This change adds `selection` data to the `TextInput.onChange` event for both iOS and Android platforms.
NOTE: `selection` only represents the cursor location when returned via `onChange` as this will not be invoked on a pure selection change without text change. We should also add this note to the documentation.
## Why
On the web, text input elements provide `selectionStart` and `selectionEnd` properties that are always accessible during input events.
React Native's `onChange` event previously included `selection` on iOS (Fabric), but this was removed in PR [facebook#51051](facebook#51051) to unify with Android (which never had it). This change restores and extends this capability to both platforms, better aligning React Native with web standards.
This is also to support pollyfill added in `react-strict-dom`; facebook/react-strict-dom#435
## What Changed
1. **iOS/macOS (C++)**: Enable selection in `onChange` event via `TextInputEventEmitter`
2. **Android (Kotlin)**: Added selection data to `ReactTextChangedEvent`
Changelog:
[General][Added] - TextInput onChange event now includes selection data (cursor location) on iOS and Android
Differential Revision: D901232951 parent 663a9c1 commit 4fc7fac
File tree
3 files changed
+11
-1
lines changed- packages/react-native
- ReactAndroid/src/main/java/com/facebook/react/views/textinput
- ReactCommon/react/renderer/components/textinput
3 files changed
+11
-1
lines changedLines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
28 | 36 | | |
29 | 37 | | |
30 | 38 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
| 143 | + | |
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| |||
0 commit comments