react-native-easy-toast, 一款简单易用的 Toast 组件,支持 Android&iOS.

2,311 阅读1分钟

A react native module to show toast like android, it works on iOS and Android.

  • 1.Run npm i react-native-easy-toast --save
  • 2.import Toast, {DURATION} from 'react-native-toast-easy'

Screenshots

Add react-native-toast-easy to your js file.

import Toast, {DURATION} from 'react-native-toast-easy'

Inside your component's render method, use Toast:

 render() {
         return (
             
                 ...
                 
             
         );
 }

Note: Add it in the bottom of the root view.

Then you can use it like this:

 this.refs.toast.show('hello world!');

That's it, you're ready to go!

render() {
        return (
            
                {
                        this.refs.toast.show('hello world!');
                    }}>
                    Press me
                
                
            
        );
    }

render() {
        return (
            
                {
                        this.refs.toast.show('hello world!',DURATION.LENGTH_LONG);
                    }}>
                    Press me
                
                
            
        );
    }

More Usage:

GitHubPopular

Props Type Optional Default Description
style View.propTypes.style true {backgroundColor: 'black',opacity: OPACITY,borderRadius: 5,padding: 10,} Custom style toast
position PropTypes.oneOf(['top','center','bottom',]) true 'bottom' Custom toast position
Method Type Optional Description
show(text, duration) function false show a toast
close() function true Close toast early

Issues are welcome. Please add a screenshot of bug and code snippet. Quickest way to solve issue is to reproduce it on one of the examples.

Pull requests are welcome. If you want to change API or making something big better to create issue and discuss it first.


MIT Licensed