react-native-easy-toast, 一款簡單易用的 Toast 組件,支持 Android&iOS.

react-native-easy-toast

React Native module to show toast like Android, it works on iOS and Android.react

Content

  • Installation
  • Demo
  • Getting started
  • API
  • Contribution

Installation

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

Demo

Getting started

Add React-native-toast-easy to your js file.android

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

Inside your component's render method, use Toast:git

render() {
         return (
             <View style={styles.container}>
                 ...
                 <Toast ref="toast"/>
             </View>
         );
 }

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

Then you can use it like this:npm

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

That's it, you're ready to Go!react-native

Basic usage

render() {
        return (
            <View style={styles.container}>
                <TouchableHighlight
                    style={{padding: 10}}
                    onPress={()=>{
                        this.refs.toast.show('hello world!');
                    }}>
                    <Text>Press me</Text>
                </TouchableHighlight>
                <Toast ref="toast"/>
            </View>
        );
    }

Custom Toast

render() {
        return (
            <View style={styles.container}>
                <TouchableHighlight
                    style={{padding: 10}}
                    onPress={()=>{
                        this.refs.toast.show('hello world!',DURATION.LENGTH_LONG);
                    }}>
                    <Text>Press me</Text>
                </TouchableHighlight>
                <Toast 
                    ref="toast" 
                    style={{backgroundColor:'red'}} 
                    position='top'
                />
            </View>
        );
    }

More Usage:

GitHubPopularide

API

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

Contribution

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.ui

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

相關文章
相關標籤/搜索