Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

textInput props textAlign will cause long text to be cut off after the hyphen when out of focus and focus again #44107

Closed
LayMui opened this issue Apr 16, 2024 · 8 comments
Labels
Component: TextInput Related to the TextInput component. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Resolution: Fixed A PR that fixes this issue has been merged.

Comments

@LayMui
Copy link

LayMui commented Apr 16, 2024

Description

textInput: When I type a very long text with a hyphen and the text exceed the view of the textInput and when I go out of focus and enter into focus again, the text after the hyphen will get cut off.
this happen for the css style textAlign props

code snippet:
<TextInput
style={styles.input}
textAlign={'left'}
/>

the above issue happen for all left, right and center

const styles = StyleSheet.create({

input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
},
..

Steps to reproduce

create the RN app
add the code snippet to the App.tsx
import {
TextInput
} from 'react-native';

<TextInput
style={styles.input}
textAlign={'center'}
/>

React Native Version

0.73.6

Affected Platforms

Runtime - iOS

Output of npx react-native info

info Fetching system and libraries information...
(node:33422) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
System:
  OS: macOS 14.4.1
  CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
  Memory: 42.90 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 21.6.2
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.21
    path: /usr/local/bin/yarn
  npm:
    version: 10.2.4
    path: /usr/local/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11076708
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    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.73.6
    wanted: 0.73.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Stacktrace or Logs

NA

Reproducer

https://github.com/LayMui/textInput

Screenshots and Videos

Screenshot 2024-04-16 at 10 16 44 AM Screenshot 2024-04-16 at 10 17 01 AM
@github-actions github-actions bot added the Component: TextInput Related to the TextInput component. label Apr 16, 2024
@LayMui LayMui changed the title textInput props textAlign will cause long text to be cut off after the hyphen when out of focus textInput props textAlign will cause long text to be cut off after the hyphen when out of focus and focus again Apr 16, 2024
@shubhamguptadream11
Copy link
Collaborator

@LayMui Can you please verify this on latest RN version: 0.74.3?

@cortinico cortinico added Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. and removed Needs: Triage 🔍 labels Jul 21, 2024
@shubhamguptadream11
Copy link
Collaborator

shubhamguptadream11 commented Jul 23, 2024

I am debugging this from a while and found out that this isn't specific to just textAlign prop.
Instead if we pass any props listed below the issue will arise
baseWritingDirection, lineBreakStrategy, lineHeight, textAlign. Common thing between these props is all are paragraphStyle props.

So what happens here is paragraphStyle will apply a default lineBreakMode=NSLineBreakByWordWrapping. Changing this to NSLineBreakByTruncatingTail will solve the issue.

Possible Solution:

  • Currently we aren't exposing lineBreakMode to RN world. So we can expose lineBreakMode to react-native world to set this attribute as well for iOS only.

Attaching file reference(Issue happening on old and new both):
Fabric:


Old Arch:
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];

@cortinico If you think this is the correct way then I can pick it up.
Issue is not coming in Android Platform
Thanks

@shubhamguptadream11
Copy link
Collaborator

@cortinico Can you look into this once.

@cortinico
Copy link
Contributor

@cortinico Can you look into this once.

We're currently hyperfocused on New Architecture bugs only at the moment as that's our P0 priority. As this is not a New Architecture bug, we can't sadly invest time on this one at the moment.

If you wish to send a PR with the change you suggested @shubhamguptadream11 please do. I can't promise it will be merged/reviewed in a timely manner at the moment, sorry for that.

@shubhamguptadream11
Copy link
Collaborator

shubhamguptadream11 commented Aug 3, 2024

@cortinico This is happening on new architecture as well. So in order to solve this issue I am thinking of exposing lineBreakMode props to react-native world as well only for iOS.
Since we can't hardcode lineBreakMode in iOS native side as this issue is coming with multiple props: baseWritingDirection, lineBreakStrategy, lineHeight, textAlign.

@cortinico
Copy link
Contributor

@cortinico This is happening on new architecture as well.

I understand, but is not a New Architecture regression.

@shubhamguptadream11
Copy link
Collaborator

@cortinico I had raised a PR here: #45968
Please check.

facebook-github-bot pushed a commit that referenced this issue Aug 23, 2024
Summary:
Solves this issue: #44107

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[IOS] [ADDED] - Line break mode for TextInput components. **This includes cpp changes and new functions.**

This PR is a breakdown of [this](#45968) PR.

Pull Request resolved: #46130

Test Plan: - Tested builds in new and old architecture mode.

Reviewed By: andrewdacenko

Differential Revision: D61656894

Pulled By: cipolleschi

fbshipit-source-id: 9a25387cb27cded072e76575e6d2fca01963c621
facebook-github-bot pushed a commit that referenced this issue Aug 23, 2024
…ons (#46129)

Summary:
Solves this issue: #44107

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[IOS] [ADDED] - Line break mode for TextInput components. **This includes  iOS updates to consume new cpp functions.**

This PR is a breakdown of [this](#45968) PR.

Pull Request resolved: #46129

Test Plan: - Tested builds in new and old architecture mode.

Reviewed By: andrewdacenko

Differential Revision: D61656969

Pulled By: cipolleschi

fbshipit-source-id: 4c6ed983ad15841ce52443bba13962d45c04e756
facebook-github-bot pushed a commit that referenced this issue Sep 10, 2024
Summary:
Solves this issue: #44107

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[IOS] [ADDED] - Line break mode for TextInput components. **This includes JS APIs for the new mode.**

This PR is a breakdown of [this](#45968) PR.

Pull Request resolved: #46128

Test Plan:
- Added unit tests to cover the new JS APIs.
- Verified that the new mode functions as expected through manual testing.

Reviewed By: andrewdacenko

Differential Revision: D61657004

Pulled By: cipolleschi

fbshipit-source-id: 9fc5c40fc077bee8e1abc51b6eae2e0f0fcd9b8f
@shubhamguptadream11 shubhamguptadream11 added the Resolution: PR Submitted A pull request with a fix has been provided. label Oct 16, 2024
@shubhamguptadream11
Copy link
Collaborator

Fixed PR had been merged. Closing this issue.
In short we now have new prop lineBreakModeIOS exposed which will handle cropping strategy.

@cortinico cortinico added Resolution: Fixed A PR that fixes this issue has been merged. and removed Resolution: PR Submitted A pull request with a fix has been provided. labels Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: TextInput Related to the TextInput component. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Resolution: Fixed A PR that fixes this issue has been merged.
Projects
None yet
Development

No branches or pull requests

3 participants