react-native: Inconsistent text behavior in TextInput between iOS and Android

Is this a bug report?

Yes

Have you read the Bugs section of the Contributing to React Native Guide?

Yes

Environment

  1. react-native -v:
react-native-cli: 2.0.1
react-native: 0.45.1

(edit: it reproduces in 0.54.2 according to the comments -@hramos)

  1. node -v: v7.7.2
  2. npm -v: 4.1.2
  3. yarn --version (if you use Yarn): N/A

Then, specify:

  1. Target Platform (e.g. iOS, Android): Android
  2. Development Operating System (e.g. macOS Sierra, Windows 10): macOS Sierra 10.12.5
  3. Build tools (Xcode or Android Studio version, iOS or Android SDK version, if relevant): Android Studio 2.3.2. Compile SDK 23. Build tools 23.0.1

Steps to Reproduce

  1. Create a TextInput that fits 100% width of the screen
  2. Set the TextInput’s value to a string that will render larger than the width of the text view
  3. Run in Android and note which part of the string renders
  4. Run in iOS and note which part of the string renders

Expected Behavior

Both iOS and Android should exhibit the same behavior and display the beginning of the text when unfocused.

Ideally, the ellipsis should also be an optional parameter to display when unfocused on both Android and iOS.

Actual Behavior

iOS displays the beginning of the text, ellipsizing the remaining text before truncating.

screen shot 2017-07-05 at 5 51 34 pm

Android displays the end of the text with no ellipsis at the beginning.

screen shot 2017-07-05 at 5 51 11 pm

Reproducible Demo

Example project: https://snack.expo.io/S1Lty1oN- To view the issue, launch the example project and preview in Android. Then preview in iOS. Note the differences between where ellipsis show and which part of the sentence displays.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 33
  • Comments: 39 (4 by maintainers)

Most upvoted comments

This issue is still going strong in 0.63.4

0.57.1 still having this issue. Very sad behavior if we have a long text in Android.

Why did you close the issue? It’s still happening

@hramos @cpojer This is still happening on latest 0.59 and 0.60. I see that you moved it to Triage Group but it’s marked as closed.

Is there any ETA on this fix? Or at least a workaround we can use, numberOfLines isn’t helping and selection property isn’t perfect and you can’t add ellipsis.

Dont we have solution for this yet?

Any news on this?

0.54.2 still having the same issue

Yes, I can confirm this is still happening on the latest version of React Native. This should be re-opened

This is still an issue in 0.61.5, is any news on this?

On RN 61.5, setting this prop:

selection={{
  start: 0,
}}

will do the good display (if not focused), but on focus, the cursor will be at start instead of at end. A possible solution would be to control the selection object with onSelectionChange and the onFocus event.

Not so sexy but it could maybe work.

This is quite bad… no solution so far

Hi @quadsurf, not sure why you would tag me as i’m not part of Google or Android team. but to answer your question. i could not reproduce the issue you mentioned. Thus i can only conclude its React Native issue.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:text="@string/app_name"
            android:textAppearance="?android:textAppearanceLarge" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:singleLine="true"
            android:text="@string/app_name"
            android:textAppearance="?android:textAppearanceLarge" />
    </LinearLayout>

</ScrollView>

screenshot_1534611564

still stuck on this in 2021! Any update on this???

still going someone can fix it ?

Still running into this issue on 0.63.3, can this be re-opened?

I can’t confirm whether it is or isn’t happening in v0.53 or v0.54

Why this issue hasn’t been solved yet ??? Its been more than 6 years

Same issue, persists in RN v0.70.0. May be any update? Proposed solutions don’t work.

selection={{
  start: 0,
}}

This fixes the head-of-the-string-getting-chopped issue, but still no ellipsis…

On RN 61.5, setting this prop:

selection={{
  start: 0,
}}

will do the good display (if not focused), but on focus, the cursor will be at start instead of at end. A possible solution would be to control the selection object with onSelectionChange and the onFocus event.

Not so sexy but it could maybe work.

  @Override
  public void setSelection(int start, int end) {
    super.setSelection(start, end);
  }

by settings the cursor position, you automatically scroll the TextInput, but this is not a good solution to this problem.

I know how to solve this and I have a pr ready for it, but I want to quickly look in the root issue of this problem.

Why are we scrolling to the end of the EditText onLoad ?? Did we override some default functioanlities included in AppCompatTextView or we missed something?

I am working on this issue