Giter VIP home page Giter VIP logo

react-native-easy-toast's Introduction

react-native-easy-toast

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

release PRs Welcome NPM version License MIT 语言 中文

Content

Installation

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

Demo

Screenshots

Getting started

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

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

Inside your component's render method, use Toast:

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

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!

Show a toast forever until you manually close it:

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

 // later on:
 this.refs.toast.close('hello world!');

Optional you can pass a delay in seconds to the close()-method:

 this.refs.toast.close('hello world!', 500);

Currently, the default delay for close() in FOREVER-mode is set to 250 ms (or this.props.defaultCloseDelay, which you can pass with)

 <Toast ... defaultCloseDelay={100} />

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'
                    positionValue={200}
                    fadeInDuration={750}
                    fadeOutDuration={1000}
                    opacity={0.8}
                    textStyle={{color:'red'}}
                />
            </View>
        );
    }

More Usage:

GitHubPopular

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
positionValue React.PropTypes.number true 120 Custom toast position value
fadeInDuration React.PropTypes.number true 500 Custom toast show duration
fadeOutDuration React.PropTypes.number true 500 Custom toast close duration
opacity React.PropTypes.number true 1 Custom toast opacity
textStyle View.propTypes.style true {color:'white'} Custom style text
Method Type Optional Description
show(text, duration) function false show a toast,unit is millisecond
close() function - start the close timer

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.

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


MIT Licensed

react-native-easy-toast's People

Contributors

crazycodeboy avatar smiche avatar itinance avatar pigarevaoks avatar wangjiejacques avatar alphasp avatar scue avatar

Watchers

Chris Trinh avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.