react-native-easy-toast, 一款简单易用的 Toast 组件,支持 Android&iOS.

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

react-native-easy-toast

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

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.

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

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!

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:

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

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值