• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

crazycodeboy/react-native-easy-toast: A react native module to show toast like a ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

crazycodeboy/react-native-easy-toast

开源软件地址:

https://github.com/crazycodeboy/react-native-easy-toast

开源编程语言:

JavaScript 100.0%

开源软件介绍:

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
    • or yarn add react-native-easy-toast
  • 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>
             ...
            <Toast ref={(toast) => this.toast = toast}/>
         </View>
     );
 }

Note: Be sure to add Toast to the bottom of the root view.

Then you can use it like this:

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

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

show a toast, and execute callback function when toast close it:

this.toast.show('hello world!', 500, () => {
    // something you want to do at close
});

Show a toast forever until you manually close it:

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

Or pass an element:

this.toast.show(<View><Text>hello world!</Text></View>);
 // later on:
 this.toast.close('hello world!');

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

 this.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>
        <Button title={'Press me'} onPress={()=>{
            this.toast.show('hello world!',2000);
        }}/>
        <Toast ref={(toast) => this.toast = toast}/>
    </View>
);
    }

Custom Toast

render() {
    return (
        <View>
            <Button title={'Press me'} onPress={()=>{
                    this.toast.show('hello world!',2000);
                }}/>
            <Toast
                ref={(toast) => this.toast = 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, callback, onPress) function false show a toast,unit is millisecond,and do callback
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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap