Commit 162627a
Add selection to TextInput onChange event (native) (#55044)
Summary:
Pull Request resolved: #55044
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 [#51051](#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`; react/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
Reviewed By: cipolleschi, javache
Differential Revision: D90123295
fbshipit-source-id: 988ce4ce737e8b297313ade8bfaa2cbbfc9758cf1 parent 625d702 commit 162627a
3 files changed
Lines changed: 12 additions & 1 deletion
File tree
- packages/react-native
- ReactAndroid/src/main/java/com/facebook/react/views/textinput
- ReactCommon/react/renderer/components/textinput
Lines 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: 2 additions & 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 | 147 | | |
| |||
0 commit comments