react / react/react-native

[Android] Content jump in multiline `TextInput` when adding/removing line of text due to delayed layout update happening after content update

Ouverte
#46,813 5 commentaires 8 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Component: TextInput Issue: Author Provided Repro p: Software Mansion Partner Platform: Android
Langage dominant
C++
Étoiles
127k
Forks
25.3k
Merge moyen
1 j 23 h
PR mergées (30 j)
4

Description

Description

When adding a new line of text in multiline TextInput component (e.g. after pressing Enter), there's a slight delay between updating the content of the text and updating the height of the component (i.e. layout) on Android with New Architecture enabled, on both New and Old Architecture.

This causes a content jump (to the top and back to the bottom) visible for one or more frames.

Before adding newline (correct):
Screenshot 2024-10-03 at 16 45 31

After pressing "Enter" (incorrect frame):
Screenshot 2024-10-03 at 16 45 39

After one or more frames (correct):
Screenshot 2024-10-03 at 16 45 47

Video recording:

https://github.com/user-attachments/assets/c0e529dc-58f6-45f3-a782-e8d65eb23ab4

Note that there's also an issue with measuring the height of the last line of the text if it's empty but it's already fixed by @j-piasecki in https://github.com/facebook/react-native/pull/42331 as well as by @NickGerleman in https://github.com/facebook/react-native/pull/46613 but the issue with content jump still persists.

Steps to reproduce
import {StyleSheet, View, TextInput} from 'react-native';

import React from 'react';

export default function App() {
  return (
    <View style={styles.container}>
      <TextInput multiline style={styles.input} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
  },
  input: {
    fontSize: 20,
    borderWidth: 1,
    borderColor: 'black',
    width: 300,
    marginTop: 100,
    padding: 0,
  },
});
React Native Version

0.76.0-rc.3

Affected Platforms

Runtime - Android

Areas

Fabric - The New Renderer

Output of npx react-native info
System:
  OS: macOS 15.0
  CPU: (12) arm64 Apple M3 Pro
  Memory: 99.83 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.19.0
    path: ~/.nvm/versions/node/v18.19.0/bin/node
  Yarn:
    version: 3.6.4
    path: ~/.nvm/versions/node/v18.19.0/bin/yarn
  npm:
    version: 10.2.3
    path: ~/.nvm/versions/node/v18.19.0/bin/npm
  Watchman:
    version: 2024.09.23.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/tomekzaw/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.0
      - iOS 18.0
      - macOS 15.0
      - tvOS 18.0
      - visionOS 2.0
      - watchOS 11.0
  Android SDK:
    API Levels:
      - "30"
      - "31"
      - "33"
      - "34"
      - "35"
    Build Tools:
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
      - 35.0.0
    System Images:
      - android-33 | Google APIs ARM 64 v8a
      - android-34 | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2412.12266719
  Xcode:
    version: 16.0/16A242d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /usr/bin/javac
  Ruby:
    version: 2.7.8
    path: /Users/tomekzaw/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.0-alpha.2
    wanted: 15.0.0-alpha.2
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.0-rc.3
    wanted: 0.76.0-rc.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false
Stacktrace or Logs
No crash or failure
Reproducer

https://github.com/tomekzaw/repro-new-arch-android-textinput

Screenshots and Videos

https://github.com/user-attachments/assets/18ac93c6-bf15-4cac-b689-760097d75ff7

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 exécuter sur Android le projet lié repro-new-arch-android-textinput et reproduire le saut de TextInput multiligne lors de l’appui sur Entrée. Lisez les chemins de layout de TextInput et de Fabric Android, ainsi que les PR associés 42331 et 46613 ; c’est terminé lorsque le contenu reste à la position attendue sans saut intermédiaire après l’ajout ou la suppression d’une ligne.

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

Évaluation

Stack technique
android, react-native
Domaine
mobile
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
42/100

Recevez les nouvelles issues par e-mail

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