import {Component} from 'react';
import Toast from 'react-native-tiny-toast';
import {setSpText} from './util';

export default class ToastBox extends Component {
  static show = content => {
    // toastShort toastLong
    if (this.toast !== undefined) {
      Toast.hide(this.toast);
    }
    this.toast = Toast.show(content.toString(), {
      duration: 2000,
      position: 0,
      shadow: true,
      animation: true,
      hideOnPress: true,
      delay: 0,
      textStyle: {fontSize: setSpText(28)}
    });
  };

  static showTop = content => {
    // toastShortTop
    if (this.toast !== undefined) {
      Toast.hide(this.toast);
    }
    this.toast = Toast.show(content.toString(), {
      duration: 2000,
      position: 100,
      shadow: true,
      animation: false,
      hideOnPress: true,
      delay: 0,
      textStyle: {fontSize: setSpText(28)}
    });
  };

  static showBottom = content => {
    // toastShortBottom
    if (this.toast !== undefined) {
      Toast.hide(this.toast);
    }
    this.toast = Toast.show(content.toString(), {
      duration: 2000,
      position: -200,
      shadow: true,
      animation: true,
      hideOnPress: true,
      delay: 0,
      textStyle: {fontSize: setSpText(28)}
    });
  };

  static loading = () => {
    if (this.toast !== undefined) {
      Toast.hide(this.toast);
    }
    this.toast = Toast.showLoading();
  };

  static hide = () => {
    if (this.toast !== undefined) {
      Toast.hide(this.toast);
    }
    this.toast = Toast.hide();
  };
}
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐