facebook / react-native

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

TextInput with Large Font Size (>40) Causes Text to Become Invisible on iOS #46002

Open enestatli opened 1 month ago

enestatli commented 1 month ago

Description

When using a TextInput component with a large fontSize (greater than 40), the text becomes invisible on iOS devices. This issue does not occur on Android, where the text is displayed correctly regardless of the font size. The problem is particularly evident when the text is long and the TextInput is set to multiline.

Steps to reproduce

  1. Create a new React Native project with the latest version.
  2. Add a TextInput component with multiline set to true.
  3. Set the fontSize of the TextInput to a value greater than 40.
  4. Provide a long string as the defaultValue or value for the TextInput.
  5. Run the app on an iOS device or simulator.

React Native Version

0.74.5

Affected Platforms

Runtime - iOS

Output of npx react-native info

System:
  OS: macOS 14.5
  CPU: (8) arm64 Apple M2
  Memory: 134.08 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.17.0
    path: ~/.nvm/versions/node/v18.17.0/bin/node
  Yarn:
    version: 3.6.4
    path: /opt/homebrew/bin/yarn
  npm:
    version: 9.6.7
    path: ~/.nvm/versions/node/v18.17.0/bin/npm
  Watchman:
    version: 2024.04.08.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/enestatli/.rbenv/shims/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:
    API Levels:
      - "29"
      - "30"
      - "31"
      - "33"
      - "33"
      - "34"
    Build Tools:
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.1
      - 33.0.2
      - 34.0.0
    System Images:
      - android-30 | Google APIs Intel x86 Atom
      - android-30 | Google Play ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
      - android-34 | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10406996
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /usr/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/enestatli/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.5
    wanted: 0.74.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Stacktrace or Logs

-

Reproducer

https://snack.expo.dev/@enestatli65/quiet-orange-strawberries

Screenshots and Videos

No response

ziggear commented 1 month ago

Hello @enestatli @cortinico I hope you're all doing well. I've been looking into this issue and came across similar cases referenced in issues #9077 and #19453. There is also a related Stack Overflow question that you can find here.

It appears that the root cause is related to the height of contentSize of a UITextView. When showing a very long text and this height reaches a very large value, such as 63863 (for my reproduce) or larger, the text does not display properly within the TextView, even though the previous 8192 limit in previous issues seems to have been removed. It seems like Apple has increased the rendering limit of the UITextView's content, but there is still a limit to the specific size.

Additionally, I have found that when you continuously add content to a UITextField that initially displays text correctly, the text continues to display properly even as the contentSize gradually exceeds a certain limit. In my tests, the contentSize has surpassed 130000 without any issues. All of these tests were conducted on iOS 17.

A potential solution is mentioned here, which might still be functional. However, I do not recommend this approach as it complicates the code, making it harder to maintain and more fragile during framework upgrades. I'm still actively working on finding a more elegant solution.

In the meantime, I suggest updating the documentation of the TextInput component to inform developers about this issue.