如何在本机反应中添加文本输入以发出警报

问题描述:

有人可以帮助将文本输入添加到 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

这是可能的.我相信这最初仅适用于 AlertIOS,但它似乎已集成到 React Native Alert.

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

虽然它被添加到 Alert 中,但它似乎不适用于 Android

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

使用

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"
    );
  };
}

更多详情:https://reactnative.dev/docs/alertios