今天踩了一个坑,Alert 在安卓环境默认点击提示框外,提示框会取消,记录一下。
我查了一下官方的中文文档,关于Alert官方是这样说的,在Android上默认情况下点击提示框的外面会自动取消提示框。有两种解决办法
1.提供一个额外参数来处理这一事件{ onDismiss: () => {} },示例如下:
// iOS和Android上都可用
Alert.alert(
'Alert Title',
'My Alert Msg',
[
{text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
{text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
{onDismiss: () => {}}
)
2.还有另外一个参数也可以用来阻止提示框被自动取消{ cancelable: false },示例如下:
// iOS和Android上都可用
Alert.alert(
'Alert Title',
'My Alert Msg',
[
{text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
{text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
{ cancelable: false }
)