react-native-paper icon indicating copy to clipboard operation
react-native-paper copied to clipboard

fix: textinput multiline with numberoflines issue #4784

Open harshaldhawale opened this issue 3 months ago • 1 comments

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.

Screenshot_2025-11-18-14-17-38-83_616845549e330d80b057239097a8ecbc~2 Screenshot_2025-11-18-14-19-57-20_616845549e330d80b057239097a8ecbc~2


[!NOTE] Ensure multiline TextInput respects numberOfLines by precomputing minHeight from themed lineHeight and applying it via contentStyle.

  • TextInput:
    • Compute lineHeight from theme (bodyLargeregular fallback → default 24).
    • Derive autoHeight for multiline with numberOfLines and apply as minHeight via contentStyle array in both TextInputFlat and TextInputOutlined.
  • Tests:
    • Update snapshots to reflect contentStyle arrays and resulting minHeight/layout changes.

Written by Cursor Bugbot for commit 4e2543e548424dc7d41bc9e562288a5d3b1bad69. This will update automatically on new commits. Configure here.

harshaldhawale avatar Nov 18 '25 08:11 harshaldhawale

Hey @harshaldhawale, thank you for your pull request 🤗. The documentation from this branch can be viewed here.

callstack-bot avatar Nov 18 '25 09:11 callstack-bot