Coder Social home page Coder Social logo

msdgwzhy6 / react-native-whc-toast Goto Github PK

View Code? Open in Web Editor NEW

This project forked from netyouli/react-native-whc-toast

1.0 1.0 0.0 1010 KB

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

Home Page: https://github.com/netyouli/react-native-whcapp

License: MIT License

JavaScript 58.86% Python 9.42% Java 7.67% Objective-C 24.05%

react-native-whc-toast's Introduction

react-native-whc-toast

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

release PRs Welcome NPM version License MIT 语言 中文

Content

Installation

  • 1.Run npm install react-native-whc-toast --save
  • 2.import Toast from 'react-native-whc-toast'

Demo

Screenshots

Getting started

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

import Toast from 'react-native-whc-toast'

Inside your component's render method, use Toast:

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

Then you can use it like this:

1.default display bottom:

 /// alert toast bottom
 this.refs.toast.show('hello toast');
 /// or
 this.refs.toast.showBottom('hello toast');

2.display top:

 /// alert toast bottom
 this.refs.toast.showTop('hello toast');
 /// or
 this.refs.toast.show('hello toast', Toast.Duration.long, Toast.Position.top);

3.display center:

 /// alert toast center
 this.refs.toast.showCenter('hello toast');
 /// or
 this.refs.toast.show('hello toast', Toast.Duration.long, Toast.Position.center);

Basic usage

render() {
        return (
            <View style={styles.container}>
                <TouchableHighlight
                    onPress={()=>{
                        this.refs.toast.show('hello toast');
                    }}>
                    <Text>Start Toast</Text>
                </TouchableHighlight>
                <Toast ref="toast"/>
            </View>
        );
    }

Custom Toast

render() {
        return (
            <View style={styles.container}>
                <TouchableHighlight
                    onPress={()=>{
                        this.refs.toast.show('hello toast', Toast.Duration.long, Toast.Position.bottom);
                    }}>
                    <Text>Start toast</Text>
                </TouchableHighlight>
                <Toast
                    ref="toast"
                    style = {styles.toast}
                    textStyle = {styles.text},
                    position = {Toast.Position.bottom}
                    fadeInDuration = {300}
                    fadeOutDuration = {300}
                    duration = {Toast.Duration.long}
                    opacity = {0.9}
                    positionValue = {100}
                />
            </View>
        );
    }

API

Position Description
Position.top toast show top
Position.center toast show center
Position.bottom toast show bottom
Duration Description
Duration.short toast default show short duration
Position.long toast default show long duration
Position.infinite toast alway show
Props Type Optional Default Description
style ViewPropTypes.style true {} Custom default toast style
textStyle Text.propTypes.style true {} Custom default toast text style
position Toast.Position true Toast.Position.bottom Custom default toast show position
fadeInDuration PropTypes.number true 300 Custom default toast fade in duration
fadeOutDuration PropTypes.number true 300 Custom default toast fade out duration
duration Toast.Duration true Toast.Duration.long Custom default toast show duration
opacity PropTypes.number true 0.9 Custom default toast fade in or fade out opacity animation
positionValue PropTypes.number true 100 Custom default toast show top, bottom margin
Method Type Optional Description
show(message, duration, position) function true show toast custom position default bottom
showTop(message, duration) function true show toast top
showCenter(message, duration) function true show toast center
showBottom(message, duration) function true show toast bottom
close(isNow) function true hide toast

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

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.