mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Fix uncontrolled multiline TextInput not expanding on iOS (#59417)
Summary: Fixes an issue where on iOS, multiline expanding TextInputs do not expand if the input starts off as empty and uncontrolled. ### Root Cause When a multiline TextInput on iOS is provided a `value` and `onChange()` prop, as shown in the [React Native docs](https://reactnative.dev/docs/textinput), the input grows as expected. However, uncontrolled inputs do not grow past the first initial line. On mount, `BaseTextInputShadowNode::updateStateIfNeeded()` writes state only if the text changes, so the first state write is skipped for empty, uncontrolled inputs. As a result, `TextAttributes` keeps the default `fontSizeMultiplier = NaN` which is carried over since iOS copies the previous state for subsequent keystrokes. During measurement, `attributedStringBoxToMeasure()` sees that the current multiplier doesn't match the stored multiplier of NaN and falls back to `props.text` which is empty for uncontrolled inputs. This causes the input to stay one-line tall. ### This PR Modify `BaseTextInputShadowNode::updateStateIfNeeded()` to update the state if base text attributes differ. On mount, the default font multiplier of NaN now differs from the real multiplier, so a state update occurs and the text field grows normally. Changelog: [iOS][Fixed] - Fix multiline TextInput not growing with its content when uncontrolled and initially empty Reviewed By: vzaidman Differential Revision: D127048714 Pull Request resolved: https://github.com/react/react-native/pull/59417
This commit is contained in:
1 parent
44c8cafa8f
commit
dc4582283b
1 file changed
+3
-1
+3
-1
@@ -157,7 +157,9 @@ class BaseTextInputShadowNode
|
||||
const auto &stateData = BaseShadowNode::getStateData();
|
||||
const auto &reactTreeAttributedString = getAttributedString(layoutContext);
|
||||
|
||||
if (stateData.reactTreeAttributedString.isContentEqual(reactTreeAttributedString)) {
|
||||
if (stateData.reactTreeAttributedString.isContentEqual(reactTreeAttributedString) &&
|
||||
stateData.reactTreeAttributedString.getBaseTextAttributes() ==
|
||||
reactTreeAttributedString.getBaseTextAttributes()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user