react / react/react-native

TextInput onKeyPress fires after the onChange

未关闭
#48,636 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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

描述

Description

According to the docs the keyPress event should fire before the change event. That does not seem to be the case though, I've run into this on a physical device in a project (doesn't use expo) I can't share and also reproduced this on a online playground for react native with expo.

In the video you can see that the console.log in the onChange callback happens before the cosnole.log in the onKeyPress callback:

https://github.com/user-attachments/assets/6e5b8cd5-6452-42a7-b315-54c911933a14

Steps to reproduce
  1. Add the onKeyPress and onChange callbacks to a TextInput
  2. Trigger both events by pressing any key on a keyboard
  3. see that onChange triggers first
React Native Version

tested on 0.74.5 and 0.76.6

Affected Platforms

Runtime - Android

Output of npx react-native info
info Fetching system and libraries information...
System:
  OS: Linux 5.10 Manjaro Linux
  CPU: (8) x64 Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
  Memory: 18.82 GB / 30.99 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.18.2
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.22
    path: /usr/local/bin/yarn
  npm:
    version: 9.8.1
    path: /usr/local/bin/npm
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
IDEs:
  Android Studio: AI-241.18034.62.2411.12169540
Languages:
  Java: Not Found
  Ruby:
    version: 2.6.8
    path: /home/owner/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.74.5
    wanted: 0.74.5
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: false
  newArchEnabled: false
Stacktrace or Logs
no logs to show
Reproducer

https://snack.expo.dev/@ncpa/rn-bug

Screenshots and Videos

No response

贡献指南

打开贡献指南

从这里开始

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

调研方向

从链接的 Snack 复现示例和 React Native TextInput 文档开始,重点关注 Android 上 onKeyPress 和 onChange 的顺序。跟踪相关的 TextInput 事件路径;如果 repository 中已有回归测试,则添加或更新该测试;当观察到的 Android 顺序与文档描述的行为一致,或文档准确反映实现时,即视为完成。

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

评估

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

把新 issue 发到你的邮箱

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