• Stars
    star
    1,093
  • Rank 42,402 (Top 0.9 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

TakePhoto

一款用于在Android设备上获取照片(拍照或从相册、文件中选择)、裁剪图片、压缩图片的开源工具库
Java
7,233
star
2

react-native-splash-screen

A splash screen for react-native, hide when application loaded ,it works on iOS and Android.
Java
5,481
star
3

RNStudyNotes

React Native 研究与实践
Objective-C
4,019
star
4

awesome-flutter-cn

一个很棒的Flutter学习资源,官方教程,插件,工具,文章,App,视频教程等的资源列表
2,883
star
5

GitHubPopular

这是一个用来查看GitHub最受欢迎与最热项目的App,它基于React Native支持Android和iOS双平台。#适配RN最新版在这里☞#
JavaScript
2,880
star
6

react-native-awesome

React Native 学习资源精选仓库(汇聚知识,分享精华)汇集了各类react-native学习资料、工具、组件、开源App、资源下载、以及相关新闻等,只求精不求全。
1,737
star
7

react-native-check-box

Checkbox component for react native, it works on iOS and Android.
JavaScript
513
star
8

flutter_splash_screen

A splash screen for flutter, hide when application loaded ,it works on iOS and Android.
Java
116
star
9

GroupListView

仿支付宝账单列表效果
Java
64
star
10

react-native-event-bus

Event bus for react native, cross-interface communication solution, it works on iOS and Android.
JavaScript
46
star
11

GitHubTrending

This is a library for fetch object data from "https://github.com/trending".
JavaScript
38
star
12

flutter_color_plugin

A color parse package for flutter,it works on iOS and Android.
Dart
22
star
13

IncrementalUpdate

Android省流量更新、增量更新、补丁生成与应用
C
21
star
14

HeadSetControl

耳机线控实例,蓝牙耳机按钮监听
Java
21
star
15

hijson

HiJson is a lightweight JSON parsing library that can be used for HarmonyOS, Android, and Java
Java
16
star
16

Ios-HomeUI

基于AutoLayout的Ios首页导航框架,支持滑动切换,TabBar切换,侧拉栏菜单等
Objective-C
14
star
17

BreakPointUploadUtil

Java断点上传工具
Java
13
star
18

crazycodeboy.github.io

https://crazycodeboy.github.io/
HTML
11
star
19

WaitScreen

Android页面加载遮罩
Java
9
star
20

ListViewPlus

带有上拉加载下拉刷新的ListView
Java
9
star
21

openai_flutter

A openai library for flutter,it works on iOS,Android,Web,macOS and Windows.
Dart
7
star
22

underline_indicator

A underline indicator
Dart
7
star
23

awesome-harmonyos

一个很棒的HarmonyOS学习资源,官方教程,插件,工具,文章,App,视频教程等的资源列表
6
star
24

PUtils

Android,Http,orm...
Java
4
star
25

KeyboardObserver

Ios键盘输入框自适应
Objective-C
4
star
26

flutter_overlay

A transparent floating layer for flutter which can programmatically show and close the child. Works on iOS,Android and Web.
Dart
3
star
27

react-native-safe-area-plus

A flexible way to handle safe area, also works on Android and iOS
JavaScript
2
star
28

flutter_hi_cache

A cache manager based on shared_preferences. Works on iOS,Android and Web.
Dart
2
star
29

gitbook-plugin-single-page

JavaScript
1
star
30

react-native-take-photo

React Native版TakePhoto@https://github.com/crazycodeboy/TakePhoto
1
star
31

react-native-navbar-plus

A react native module to show navbar,it works on iOS and Android.
JavaScript
1
star
32

flutter_nested

Lists that support nested scrolling can customize the header and the number of lines displayed per line.
Dart
1
star
33

react-native-isiphonex-device

A react native module to replace DeviceInfo.isIPhoneX_deprecated.
TypeScript
1
star
34

DigitalTimer

自定义数字时钟
Java
1
star