question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextInput] [android] setNativeProps({text:<string>}) repeats characters

See original GitHub issue

🐛 Bug Report

Setting the text of a TextInput on Android via setNativeProps({text:<string>}) repeats existing characters

iOS Android
ezgif-5-d41d630c6023 ezgif-5-cc5ea23a941c

To Reproduce

Add a TextInput in Android and capture a ref to it. Add an onChangeText handler to the TextInput, and in this, set the text of the input to some function of the current text.

As characters are typed into the input, the text will repeat previously input characters in addition to the value of the string used in setNativeProps.

Expected Behavior

Setting the text via setNativeProps({text:<string>}) should set the text of the input to just <string> with no repeated characters.

Code Example

On latest react native, via react-native init

import React, {Component} from 'react';
import {Text, View, TextInput} from 'react-native';

type Props = {};
export default class App extends Component<Props> {
    render() {
        return (
            <View style={{paddingTop:200}}>
                <TextInput style={{width:"100%",backgroundColor:"yellow"}}
            ref={(r)=>this.textInputRef=r} onChangeText={(t)=>this.textInputRef.setNativeProps({text:t.toUpperCase()})}>
                </TextInput>
            </View>);
    }
}

Link to snack: https://snack.expo.io/Hk-z-q3FV

Environment

React Native Environment Info: System: OS: macOS 10.14.4 CPU: (8) x64 Intel® Core™ i7-4770HQ CPU @ 2.20GHz Memory: 216.29 MB / 16.00 GB Shell: 5.3 - /bin/zsh Binaries: Node: 8.15.1 - ~/.nvm/versions/node/v8.15.1/bin/node Yarn: 1.12.3 - ~/.yarn/bin/yarn npm: 6.4.1 - ~/.nvm/versions/node/v8.15.1/bin/npm Watchman: 4.7.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2 Android SDK: API Levels: 25, 26, 27, 28 Build Tools: 25.0.3, 28.0.3, 29.0.0 System Images: android-28 | Google APIs Intel x86 Atom IDEs: Android Studio: 2.3 AI-162.3871768 Xcode: 10.2/10E125 - /usr/bin/xcodebuild npmPackages: react: 16.8.3 => 16.8.3 react-native: 0.59.4 => 0.59.4

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
anees-syookcommented, Oct 14, 2019

This issue is still happening in react-native 0.59.10

<TextInput
   name={name}
   value={value}
   returnKeyType={'done'}
   autoCorrect={false}
   onChangeText={value => onInputChange(name, value.toUpperCase())}
   onBlur={() => onInputBlur(name)}
/>

image

0reactions
lordpranacommented, Feb 28, 2022

I’m encountering this issue on Android on react-native 0.64.3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react native textinput ref value - You.com | The AI Search ...
Setting the text via setNativeProps({text:<string>}) should set the text of the input to just <string> with no repeated characters.
Read more >
React Native: TextInput toUpperCase does not work on ...
The first two letters work fine, but whenever I add a third letter, it suddenly repeats the first two letters so that ABC...
Read more >
Editable View labels - Android Accessibility Help
To label an editable TextView or EditText , use android:hint to display a descriptive text label within the item when it's empty.
Read more >
Accessible Text Input in Android: Using the labelFor Attribute
Android provides the accessibility framework for EditText objects but it is important to know how & when to use the built-in tools.
Read more >
TextInput - React Native
Note that on Android performing text selection in an input can change ... Tells TextInput to automatically capitalize certain characters.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found