Skip to content

[Android] [TextInput] selection property has no effect #22513

Description

@jamsch

Environment

Run react-native info in your terminal and paste its contents here.

  React Native Environment Info:
    System:
      OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
      CPU: x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
      Memory: 1.12 GB / 15.54 GB
      Shell: 4.4.19 - /bin/bash
    Binaries:
      Node: 10.9.0 - ~/.nvm/versions/node/v10.9.0/bin/node
      Yarn: 1.10.1 - /usr/bin/yarn
      npm: 6.4.1 - ~/.nvm/versions/node/v10.9.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      Android SDK:
        Build Tools: 23.0.1, 23.0.2, 23.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 27.0.0, 27.0.1, 27.0.3
        API Levels: 23, 24, 25, 26, 27
    npmPackages:
      @storybook/react-native: 4.0.11 => 4.0.11
      @types/react: ^16.7.13 => 16.7.13
      @types/react-native: ^0.57.17 => 0.57.17
      react: ^16.6.3 => 16.6.3
      react-native: 0.57.7 => 0.57.7

Description

So I have this TextInput component that's supposed to toggle between secureTextEntry, a common use case for showing/hiding password. The issue is that the text selection is reset to the start of the input and I can't find a way to set the cursor position to the end after toggling "show/hide password".

In other words, setting the property selection={{ start: number, end: number }} on a TextInput element seems to do nothing.

What's been attempted:

  1. Setting the selection state after a button click event.
  2. Updating selection state after the onSelectionChange event
  3. Using textInputRef.current.setNativeProps({ selection: {} }) on componentDidUpdate

Image:

peek 2018-12-05 11-40

Reproducible Demo

https://snack.expo.io/HkvTKtEkN

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions