Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a text input to alert in react native

Tags:

react-native

Can someone help with adding a text input to an alert in react native. Is it possible? I searched and found results that deals with multiple line text input which is not the case with me. Thanks in advance

like image 520
Devika Avatar asked Mar 12 '19 06:03

Devika


People also ask

Can I style alert in react-native?

React Native Alert does not support custom styling and animations. If your requirements for the same, we recommend using the React Native Modal. React native Modal can be used as an alert also and it has more functionalities, animations, and styling options as compared to the react-native alert component.


1 Answers

This is possible. I believe this was only available initially for AlertIOS however it seems to have been intergrated to React Native Alert.

Edit: Although its added to Alert it does not seem to work for Android

Use

import { Alert } from 'react-native'; 

onButtonPress = () => {
    Alert.prompt(
      "Enter password",
      "Enter your password to claim your $1.5B in lottery winnings",
      [
        {
          text: "Cancel",
          onPress: () => console.log("Cancel Pressed"),
          style: "cancel"
        },
        {
          text: "OK",
          onPress: password => console.log("OK Pressed, password: " + password)
        }
      ],
      "secure-text"
    );
  };
}

More details: https://reactnative.dev/docs/alertios

like image 94
Dihan Avatar answered Sep 17 '22 13:09

Dihan