我在 React Native 中有一个 TextInput AlertIOS:
AlertIOS.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) => password.trim() != "" ? Dismiss ALERT : KEEP ALERT,
},
],
'secure-text',
);
有没有办法仅以编程方式消除警报? 即,当单击非取消选项时,我想仅在条件成立时才关闭警报。
这可能吗?
如果您想在
点击按钮时关闭警报Cancel
您可以像这样创建一个空函数onPress: () => {}
而不是console.log()
。如果要在条件成立时关闭警报,可以尝试以下操作:
onPress: (password) => password.trim() !== "" ? this.doSomething() : this.doAnotherStuff();
或
onPress: (password) => password.trim() !== "" ? this.doSomething() : () => {};