react / react/react-native

TextInput with multiline and fixed height shows inconsistent text positioning on initial render

未关闭
#54,304 7 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Component: TextInput Needs: Triage :mag:
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

Description

When using a TextInput with multiline={true}, fixed height, and textAlignVertical="top", the text positioning is inconsistent depending on navigation path. When a user first opens the app and navigates to a screen containing long text that overflows the TextInput, the text appears "squashed" towards the top with content cut off under the border. However, if the user navigates back to the home screen, opens a note with shorter content first, then returns to the long note, the text positioning displays correctly.

This appears to be a layout initialization timing issue where the TextInput doesn't properly calculate its content positioning on first render when dealing with overflow content.

Steps to reproduce
  1. Clone the reproduction repository: git clone https://github.com/Jakes-Git-Hub/Multi-Line-Test.git
  2. Install dependencies with npm install
  3. Start the app with npx expo start
  4. Open the app and immediately tap on either "Long Note Example" or "Another Overflow Note"
  5. Observe that the text appears squashed towards the top with content cut off under the border
  6. Navigate back to the home screen using the back button
  7. Tap on the "Short" note (single word content)
  8. Navigate back and tap on one of the long notes again
  9. Observe that the text now displays correctly with proper positioning

Also if i go into another long note after initially opening a long note, the text positioning adjusts to a middle ground between squashed and what would be the text position if sequence was long note -> short note -> LN.

React Native Version

0.81.5

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info
System:
  OS: Windows 11 10.0.26100
  CPU: (12) x64 12th Gen Intel(R) Core(TM) i7-1255U
  Memory: 1.77 GB / 15.68 GB
Binaries:
  Node:
    version: 22.14.0
    path: C:\Program Files\nodejs\node.EXE
  Yarn: Not Found
  npm:
    version: 11.6.2
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK: Not Found
IDEs:
  Android Studio: Not Found
  Visual Studio: Not Found
Languages:
  Java: Not Found
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 19.1.0
    wanted: 19.1.0
  react-native:
    installed: 0.81.5
    wanted: 0.81.5
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
Stacktrace or Logs
No crash occurs - this is a layout/rendering issue. The TextInput renders but with incorrect text positioning on initial load. No error messages or stack traces are generated.
MANDATORY Reproducer

https://github.com/Jakes-Git-Hub/Multi-Line-Test

Screenshots and Videos

https://github.com/user-attachments/assets/567f5f49-a871-4b1a-8614-4208b0c13a1f

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 React Native 0.81.5 运行必需的 Multi-Line-Test 复现步骤,并比较 iOS 上初始的长笔记路径与短笔记导航路径。调查固定高度、内容溢出以及 textAlignVertical="top" 时多行 TextInput 的行为。当长笔记在首次渲染和导航后都具有一致的文本位置,且内容不会在边框下方被截断时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
ios, react-native
领域
mobile
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。