facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
117.1k stars 24.07k forks source link

`TextInput.onKeyPress`: `nativeEvent.key` is an empty string when a non-ASCII character is entered #45199

Closed pklatka closed 14 hours ago

pklatka commented 1 week ago

Description

When a non-ASCII character is entered in the TextInput component, onKeyPress does not return proper key value. This issue doesn't exist on old architecture.

Steps to reproduce

  1. Clone the reproducer
  2. Install project dependencies with npm
  3. Run the app with npm run ios
  4. Try entering non-ASCII characters (e.g., characters with accents, Cyrillic, Chinese characters, emoji) in the TextInput
  5. Observe that the onKeyPress does not return the correct values for these characters.

React Native Version

0.74.2

Affected Platforms

Runtime - iOS

Areas

Fabric - The New Renderer

Output of npx react-native info

System:
  OS: macOS 14.5
  CPU: (11) arm64 Apple M3 Pro
  Memory: 99.61 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.11.1
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.21
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.2.4
    path: /usr/local/bin/npm
  Watchman:
    version: 2024.05.06.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.3 AI-233.14808.21.2331.11709847
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 18.0.2
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.2
    wanted: 0.74.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

This issue isn't a crash or failure.

Reproducer

https://github.com/pklatka/non-ascii-key-press-repro

Screenshots and Videos

New architecture Old architecture
pklatka commented 1 week ago

I guess that this might be caused by how keyPressMetricsPayload is implemented - the key which is passed to the event object is always a one char.

arushikesarwani94 commented 4 days ago

And by

Run the app with npm run ios or npm run android

I assume it's happening both on Android & iOS or just an iOS thing since it might be caused by iostextinput ?

pklatka commented 4 days ago

I could only reproduce that on iOS (I forgot to update this repro step 😕)

arushikesarwani94 commented 2 days ago

The problem is also entering non ASCII character (é) is being registered as onChange event instead of onKeyPress

arushikesarwani94 commented 17 hours ago

@pklatka @deepanshushuklad11 Can you try https://github.com/facebook/react-native/pull/45274 with Cyrillic, Chinese characters. I have verified it works for accent letters & Emojis on iOS.