1.0.0 • Published 6 years ago

react-native-whc-toast v1.0.0

Weekly downloads
13
License
MIT
Repository
github
Last release
6 years ago

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.bottom);

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

PositionDescription
Position.toptoast show top
Position.centertoast show center
Position.bottomtoast show bottom
DurationDescription
Duration.shorttoast default show short duration
Position.longtoast default show long duration
Position.infinitetoast alway show
PropsTypeOptionalDefaultDescription
styleViewPropTypes.styletrue{}Custom default toast style
textStyleText.propTypes.styletrue{}Custom default toast text style
positionToast.PositiontrueToast.Position.bottomCustom default toast show position
fadeInDurationPropTypes.numbertrue300Custom default toast fade in duration
fadeOutDurationPropTypes.numbertrue300Custom default toast fade out duration
durationToast.DurationtrueToast.Duration.longCustom default toast show duration
opacityPropTypes.numbertrue0.9Custom default toast fade in or fade out opacity animation
positionValuePropTypes.numbertrue100Custom default toast show top, bottom margin
MethodTypeOptionalDescription
show(message, duration, position)functiontrueshow toast custom position default bottom
showTop(message, duration)functiontrueshow toast top
showCenter(message, duration)functiontrueshow toast center
showBottom(message, duration)functiontrueshow toast bottom
close(isNow)functiontruehide 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