react / react/react-native

TextInput abnormal behaviour of setNativeProps for updating selection

Ouverte
#54,163 5 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Component: TextInput Issue: Author Provided Repro Type: New Architecture
Langage dominant
C++
Étoiles
127k
Forks
25.3k
Merge moyen
1 j 23 h
PR mergées (30 j)
4

Description

Description

This repository reproduces a bug in React Native where calling setNativeProps with the selection property on a TextInput component fails to update the cursor position or text selection as expected. The issue started happening after migrating to New architecture. Legacy architecture handles same logic without issues.

When attempting to programmatically control text selection in a TextInput using setNativeProps({ selection: { start, end } }), the following issues occur:

  • The cursor position does not update on Android
  • The cursor jump abnormally on iOS
  • Selection changes are ignored or behave inconsistently
  • iOS and Android exhibit different behaviors
Steps to reproduce
  1. Open the snack link
  2. Tap on first button to set initial text

First line of text should be selected, but it does not work on Android

  1. Reposition the cursor to centre of text by tapping
  2. Press second button to add img link -

iOS side bug will appear on this step, cursor jumps to wrong position

  1. Press third button to select all

Both android and iOS will fail

  1. Tap on fourth button insert md bold block

On both android and ios, cursor gets placed on either start or end, instead of being placed at **|**

React Native Version

0.79.5

Affected Platforms

Runtime - iOS, Runtime - Android

Areas

JSI - Javascript Interface

Output of npx @react-native-community/cli info
System:
  OS: macOS 15.2
  CPU: (10) arm64 Apple M4
  Memory: 141.75 MB / 24.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 24.5.0
    path: /opt/homebrew/opt/node@21/bin/node
  Yarn:
    version: 1.22.22
    path: ~/Documents/ReactNativeProjects/ecency-mobile/node_modules/.bin/yarn
  npm:
    version: 11.5.1
    path: /opt/homebrew/opt/node@21/bin/npm
  Watchman:
    version: 2025.03.10.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.4
      - iOS 18.4
      - macOS 15.4
      - tvOS 18.4
      - visionOS 2.4
      - watchOS 11.4
  Android SDK:
    API Levels:
      - "28"
      - "30"
      - "31"
      - "33"
      - "34"
      - "35"
    Build Tools:
      - 28.0.3
      - 29.0.2
      - 29.0.3
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.1
      - 33.0.2
      - 34.0.0
      - 35.0.0
      - 35.0.0
      - 35.0.0
    System Images:
      - android-29 | Google Play ARM 64 v8a
      - android-30 | Google Play ARM 64 v8a
      - android-31 | Google APIs ARM 64 v8a
      - android-31 | Google Play ARM 64 v8a
      - android-32 | Google APIs ARM 64 v8a
      - android-32 | Google Play ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
      - android-33 | Google Play ARM 64 v8a
      - android-34 | Google APIs ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
      - android-36.1 | Google Play ARM 64 v8a
      - android-36 | Google Play ARM 64 v8a
      - android-Baklava | Pre-Release 16 KB Page Size Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2025.1 AI-251.25410.109.2511.13752376
  Xcode:
    version: 16.3/16E140
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.5
    path: /usr/bin/javac
  Ruby:
    version: 3.4.2
    path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 18.0.0
    wanted: 18.0.0
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.79.5
    wanted: 0.79.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: true
Stacktrace or Logs
Not applicable
MANDATORY Reproducer

https://snack.expo.dev/@noumantahir/textinput-setnativeprops-selection-bug

Screenshots and Videos

Android Response
https://github.com/user-attachments/assets/55dfa9b3-3a8a-4708-a193-c2cfaab5c2e1

iOS Response
https://github.com/user-attachments/assets/2dd095ed-60a1-4ecf-a31a-534df6d90983

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par le reproducteur Snack obligatoire et comparez le comportement de sélection de TextInput avec setNativeProps sur Android et iOS dans le cadre de la New architecture. Suivez le chemin de mise à jour de la sélection de TextInput à partir de setNativeProps ; le travail est considéré comme terminé lorsque le positionnement du curseur et la sélection du texte correspondent aux positions attendues sur les deux plateformes.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, react-native
Domaine
mobile-dev
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
30/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.