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.

Toggling secureTextEntry between true and false cause text to disappear on iOS

See original GitHub issue

Description

I’m trying to create a custom password input where you can toggle if you can see the password or not. The bug is that when you change between true and false on textInput, the content of the input disappear.

Reproduction

First, you need to have a textInput with secureTextEntry. Then you enter a string in the textinput. After that you set the secureTextEntry to false and then back to true and you enter another character. The field should be set empty and then the new character appear.

On android, the cursor is set to the beginning of the field you do the same steps.

Solution

I found that the onChangeText props of the TextInput return an empty string when you set secureTextEntry to true.

Additional Information

React Native version : 0.41 Platform: iOS and Android OS : MacOS

Here’s a simple example of what I’m trying to do :

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

export default class test_secureTextEntry extends Component {
  constructor(props) {
        super(props);
        this.state = {
          hidden: true
        };
    }

  render() {
    return (
      <View style={styles.container}>
        <TextInput
          secureTextEntry={this.state.hidden}
          style={{ width: 100, height: 40, backgroundColor: 'grey' }}
        />
        <TouchableOpacity
          onPress={ () => this.setState({ hidden: !this.state.hidden })}
        >
          <Text>Go</Text>
        </TouchableOpacity>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  }
});

AppRegistry.registerComponent('test_secureTextEntry', () => test_secureTextEntry);

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
nateReinerscommented, Feb 7, 2018
  • 1 this is still an issue for me (RN 0.50.3) and this should be re-opened
3reactions
altaf933commented, Jun 20, 2018

I have same issue on react-native version react-native: 0.55.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

TextInput clears text when secureTextEntry is true
Unfortunately, it seems that Osiel Lima is correct, and this is indeed the intended behavior for iOS. It's very poorly designed behavior, IMHO, ......
Read more >
secureTextEntry | Apple Developer Documentation
A Boolean value that indicates whether a text object disables copying, and in some cases, prevents recording/broadcasting and also hides the text.
Read more >
TextInput - React Native
If true , the text input can be multiple lines. The default value is false . It is important to note that this...
Read more >
Password TextInput in React-Native | by Swair AQ - Medium
onChangeText(text)}onFocus={() => setFocus(true)}onBlur={() => setFocus(false)}secureTextEntry={secure} //we just added thisstyle={styles.
Read more >
Kony Widget User Guide
In iOS and Android platforms, matrix multiplication is used between the steps to ... doLayout of any widget since this might cause application...
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