Skip to content

alertView

brainpoint edited this page Mar 2, 2017 · 3 revisions

Example


'use strict';
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, } from 'react-native';
import { AlertView } from 'react-componet';

class app extends Component {
  show() {
    AlertView.showAlert('content', [{text:'ok'}]);
  }

  render() {
    return (
      <AlertView>
      </AlertView>
    );
  }
}
AlertView包含 `模态对话框` , `加载视图` , `消息提示框` ;
将AlertView包裹在render的最外层, 全局只有一个alertView时可以使用static方法或this成员方法调用功能, 若存在多个则使用this成员方法调用.

Gloabl style.


AlertView.setDefaultStyle({buttonContainerStyle, viewStyle, toastViewStyle, loadingViewStyle});

调用此方法设置全局默认样式.

Alert.


AlertView.hideAlert();

隐藏对话框.

AlertView.isHiddenAlert();

查看对话框当前是否是隐藏.

AlertView.showAlert(content, buttonArray = null, buttonContainerStyle = null, viewStyle = null)

显示对话框.

  • param ** content ** 显示的内容. 可以为以下类型的数据:

    1.属性对象

      {
       text:       PropTypes.string,   // 显示文本.
       tintColor:  PropTypes.string,   // 文本颜色.
       style:      PropTypes.object,   // 文本样式.
      }

2.或者为react元素,如<Text></Text>

3.或者直接为string

  • param ** buttonArray ** 按钮数组. 可以为如下类型的数据:

    1.属性对象

      {
       isDefault: PropTypes.boolean,            // 只能有一个按钮为默认, 点击后将自动关闭对话框.
       text:      PropTypes.string.isRequired,  // 显示文本.
       tintColor: PropTypes.string,             // 文本颜色.
       onPress:   PropTypes.func,               // 点击事件. function(alertView, index), 参数为控件及按钮的索引.
       style:     PropTypes.object,             // 文本样式.
      }

2.或者为react元素,如<Text></Text>

  • param buttonContainerStyle 按钮数组的容器样式. 默认样式为 2个按钮以下按行排列, 2个按钮以上按列排列.

  • param viewStyle 警告框样式.

Loading.


AlertView.hideLoading();

隐藏加载框.

AlertView.isHiddenLoading();

判断加载框是否是隐藏.

AlertView.showALoading(content, viewStyle = null)

显示加载框.

  • param content 显示的内容. 可以为如下类型的数据:

    1.属性对象

      {
       text:       PropTypes.string,   // 显示文本.
       tintColor:  PropTypes.string,   // 文本颜色.
       style:      PropTypes.object,   // 文本样式.
      }

2.或者为react元素,如<Text></Text>

3.或者直接为string

  • param viewStyle 警告框样式.

Toast.


AlertView.toast(content, timeoutHide = 2000, viewStyle = null)

显示提示框. 提示框将在短时间内自动关闭.

  • param content 显示的内容.

    1.属性对象

      {
       text:       PropTypes.string,   // 显示文本.
       tintColor:  PropTypes.string,   // 文本颜色.
       style:      PropTypes.object,   // 文本样式.
      }

2.或者为react元素,如<Text></Text>

3.或者直接为string

  • param timeoutHide 多久之后自动关闭

  • param viewStyle 警告框样式.