react-native-root-toast

封装成组件

import React , {  Component } from  'react';
import {
  AppRegistry,
  StyleSheet,
  View,
  Text,
} from 'react-native';

import Toast from 'react-native-root-toast';

export default class MyToast extends Component {

  constructor(props){
    super(props);
    this.state = {

    };
  }

  render() {
    return (
      
           {
              var p = Toast.positions.BOTTOM;
              if(this.props.position == 'top'){
                  p = Toast.positions.TOP;
              }else if(this.props.position == 'center'){
                  p = Toast.positions.CENTER;
              }

              let toast = Toast.show(this.props.message, {
                duration: this.props.duration == 'LONG' ? Toast.durations.LONG : Toast.durations.SHORT,
                position: p,
                shadow: true,
                animation: true,
                hideOnPress: true,
                delay: 0,
                onShow: () => {
                    // calls on toast\`s appear animation start
                },
                onShown: () => {
                    this.props.showEndEvent && this.props.showEndEvent();
                    // calls on toast\`s appear animation end.
                },
                onHide: () => {
                    // calls on toast\`s hide animation start.
                },
                onHidden: () => {
                    // calls on toast\`s hide animation end.
                }
               });
            //    setTimeout(function(){
            //        Toast.hide(toast);
            //    },500);

              }}>{this.props.children}
      
    )
  }

}

const styles = StyleSheet.create({
});


你可能感兴趣的:(react-native-root-toast)