iOS only: `onChangeText` of `TextInput` is fired with text longer than `maxLength`
还没有人认领这个 Issue。
- 主要语言
- C++
- 星标
- 127k
- 派生
- 25.3k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 4
描述
Description
We noticed that sometimes the onChangeText event of TextInput was fired with text longer than maxLength. According to the doc, this behaviour seems to be unexpected.
maxLength:
Limits the maximum number of characters that can be entered.
This happens only on iOS relating to autocompletion.
Steps to reproduce
Here is a snack link to reproduce the issue: https://snack.expo.dev/@yupeng_li/textinput
It contains only a TextInput component and maxLength is set to 3. If you type in bef and let the autocomplete suggestion come up, you will see an alert triggered by onChangeText when text is longer the maxLength.
In the screenshot below, the text returned is "Before", and the text displayed in the input is "ore".
React Native Version
0.71.14
Affected Platforms
Runtime - iOS
Output of npx react-native info
info Fetching system and libraries information...
System:
OS: macOS 14.1.2
CPU: (10) arm64 Apple M1 Pro
Memory: 81.80 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.17.0 - ~/Library/Caches/fnm_multishells/24849_1670237417415/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.6.7 - ~/Library/Caches/fnm_multishells/24849_1670237417415/bin/npm
Watchman: 2023.10.09.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: Not Found
SDKs:
iOS SDK:
Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0
Android SDK: Not Found
IDEs:
Android Studio: 2022.3 AI-223.8836.35.2231.10671973
Xcode: 15.0.1/15A507 - /usr/bin/xcodebuild
Languages:
Java: 11.0.19 - /Users/yupeng/.sdkman/candidates/java/11.0.19-tem/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.14 => 0.71.14
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
info React Native v0.73.0 is now available (your project is running on v0.71.14).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.73.0
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.71.14
info For more info, check out "https://reactnative.dev/docs/upgrading".
Stacktrace or Logs
No stacktrace
Reproducer
https://snack.expo.dev/@yupeng_li/textinput
Screenshots and Videos
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 Snack reproducer 以及 iOS 上 TextInput onChangeText/maxLength 的行为入手,尤其要关注 autocomplete 插入文本时的情况。跟踪 iOS TextInput 的入口点,以确定为什么字段显示“ore”,而 callback 却接收到“Before”。当 autocomplete 无法使 onChangeText 报告长度超过 maxLength 的文本,并且 reproducer 的行为已修正时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- ios, react-native
- 领域
- mobile
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100