反应本机警报

时间:2019-07-04 03:00:19

标签: react-native alert

我想从这些图标中发出警告,说出图标的描述。因此,当您按下一个显示警报的图标时,我的问题是如何定义每个图标的警报标题和消息,标题将是图标名称,消息将是描述

1

我的图标代码看起来像这样

    let status = item[keys['status']];
    panel.push(<View style={{ position: 'absolute', right: 0, bottom: 0, padding: normalize(5), alignItems: 'center' }} key={'status'}>
      <TouchableOpacity onPress={()=>alert()}>
        <Icon name={img.itemStatus[status].name} type={img.itemStatus[status].type} color={img.itemStatus[status].color} size={normalize(38)} />
      </TouchableOpacity>
    </View>);

1 个答案:

答案 0 :(得分:0)

将警报标题作为参数传递, 例如:

...

_showAlert(title, message) {
 Alert.alert(
  title,
  message,
  [
    {
      text: cancelText,
      style: "cancel"
    },
    {
      text: okText,
      onPress: () => {
        //Did tap on Ok
      }
    }
  ],
  { cancelable: true }
);
}
...

let status = item[keys['status']];
let title = 'Alert Title' // Define your title here
let message = 'Alert Message' // Define your message here
    panel.push(<View style={{ position: 'absolute', right: 0, bottom: 0, padding: normalize(5), alignItems: 'center' }} key={'status'}>
      <TouchableOpacity onPress={()=>this._showAlert(title, message)}>
        <Icon name={img.itemStatus[status].name} type={img.itemStatus[status].type} color={img.itemStatus[status].color} size={normalize(38)} />
      </TouchableOpacity>
    </View>);
...