0

Currently when I set the secureTextEntry to true, all the password symbols become circles: enter image description here

What I want to achieve is to show stars instead of circles. Here is an example: enter image description here

*notice the stars in the second image

Thank you mates in advance!

spatak
  • 1,039
  • 1
  • 14
  • 25

1 Answers1

0

We cannot override that dot we see in the TextInput field. But we can try a workaround.

You can handle the input value using the onKeyPress prop that TextInput provides.

Below is the onKeyPress function that you can use. Note: setPassword is a state updating function.

const onKeyPress = (data: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
  if (data.nativeEvent.key === 'Backspace') {
    setPassword(password.slice(0, -1));
    return;
  }

  if (data.nativeEvent.key === 'Enter') {
    // On Enter handle here
    return;
  }

  if (data.nativeEvent.key === ' ') {
    setPassword(password + ' ');
    return;
  }

  if (data.nativeEvent.key === 'Tab') {
    // On Tab handle here
    return;
  }

  setPassword(password + data.nativeEvent.key);
};

And in the TextInput component, you can use it like this

<TextInput
  style={styles.textInput}
  placeholder="Password"
  value={'*'.repeat(password.length)} // This is important.
  onKeyPress={onKeyPress}
/>

Here is an Expo Snack that you can refer to. It has a working implementation. It has been tested for Android and iOS only.

Kartikey
  • 4,516
  • 4
  • 15
  • 40