fix: textinput multiline with numberoflines issue #4784
Problem
When using <TextInput multiline numberOfLines={x} />, the component does not respect the specified number of lines. The height remains fixed, causing layout issues and requiring manual intervention from the developer.
Motivation
The internal height calculation logic runs after layout instead of before render. Because of this, the initial height is not correctly set based on numberOfLines. The native height is applied later, leading to a mismatch.
Solution
- Added logic to correctly derive the initial height from numberOfLines before render.
- Ensure multiline height updates run during initialization instead of post‐layout.
- Prevent overrides when the user provides a custom height.
Related issue
#4784 – TextInput with multiline and numberOfLines does not correctly adjust height
Test plan
- Render <TextInput multiline numberOfLines={4} /> → height should match 4 lines.
- Change numberOfLines dynamically → height should update correctly.
- Custom style={{ height: ... }} should override default behavior.
- Snapshot tests updated accordingly.
[!NOTE] Ensure multiline TextInput respects numberOfLines by precomputing minHeight from themed lineHeight and applying it via contentStyle.
- TextInput:
- Compute
lineHeightfrom theme (bodyLarge→regularfallback → default24).- Derive
autoHeightformultilinewithnumberOfLinesand apply asminHeightviacontentStylearray in bothTextInputFlatandTextInputOutlined.- Tests:
- Update snapshots to reflect
contentStylearrays and resulting minHeight/layout changes.Written by Cursor Bugbot for commit 4e2543e548424dc7d41bc9e562288a5d3b1bad69. This will update automatically on new commits. Configure here.
Hey @harshaldhawale, thank you for your pull request 🤗. The documentation from this branch can be viewed here.