Commit 4bbb042
committed
Fix uncontrolled multiline TextInput not resizing when children change
## Summary
When a multiline TextInput uses children (attributed text) instead of the
`value` prop (uncontrolled mode), changing the children does not cause the
TextInput to resize. For example, clearing children after sending a message
leaves the input at its expanded multi-line height.
## Root Cause
`measureContent()` is called by Yoga during `YGNodeCalculateLayout`, which
runs BEFORE `updateStateIfNeeded()` in the `layout()` callback. In
`attributedStringBoxToMeasure()`, when the state is meaningful and the
`attributedStringBox` is non-empty, it returns the stale native text for
measurement — even though the React tree (children) has already changed.
The sequence:
1. User types multiline text → native `_updateState()` updates
`attributedStringBox` with the typed text
2. User clears text (e.g. sends message) → React children become empty
3. Yoga calls `measureContent()` → `attributedStringBoxToMeasure()` returns
the stale multi-line text → height stays expanded
4. `updateStateIfNeeded()` runs later and updates state, but the layout
has already been computed with the wrong size
## Fix
In `attributedStringBoxToMeasure()`, check if the React tree attributed
string has diverged from what's stored in state. If so, use the React tree
version for measurement instead of the stale `attributedStringBox`. This
ensures Yoga measures with the correct content when children change between
layout passes.
## Changelog
[iOS][Fixed] - Fix uncontrolled multiline TextInput not resizing when children change
Fixes #545701 parent 2d78a39 commit 4bbb042
File tree
1 file changed
+18
-0
lines changed- packages/react-native/ReactCommon/react/renderer/components/textinput
1 file changed
+18
-0
lines changedLines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
207 | 225 | | |
208 | 226 | | |
209 | 227 | | |
| |||
0 commit comments