Coder Social home page Coder Social logo

react-xx / react-native-root-toast Goto Github PK

View Code? Open in Web Editor NEW

This project forked from magicismight/react-native-root-toast

0.0 1.0 0.0 4.22 MB

react native toast like component, pure javascript solution

License: MIT License

JavaScript 77.33% Java 3.88% Objective-C 18.79%

react-native-root-toast's Introduction

react-native-root-toast


Features

  1. Pure javascript solution.
  2. Support both Android and iOS.
  3. Lots of custom options for Toast.
  4. You can show/hide Toast by calling api or using Component inside render.

screen-shoots

Install

npm install react-native-root-toast

Settings

Name Default Type Description
duration Toast.durations.SHORT Number The duration of the toast. (Only for api calling method)
visible false Bool The visibility of toast. (Only for Toast Component)
position Toast.positions.BOTTOM Number The position of toast showing on screen (A negative number represents the distance from the bottom of screen. A positive number represents the distance form the top of screen. 0 will position the toast to the middle of screen.)
animation true Bool Should preform an animation on toast appearing or disappearing.
shadow true Bool Should drop shadow around Toast element.
delay 0 Number The delay duration before toast start appearing on screen.
onShow null Function Callback for toast`s appear animation start
onShown null Function Callback for toast`s appear animation end
onHide null Function Callback for toast`s hide animation start
onHidden null Function Callback for toast`s hide animation end

Properties

Toast.durations

presets of duration of the toast.

  1. Toast.durations.SHORT (equals to 2000)

  2. Toast.durations.LONG (equals to 3500)

Toast.positions

presets of position of toast.

  1. Toast.positions.TOP (equals to 20)

  2. Toast.positions.BOTTOM (equals to -20)

  3. Toast.positions.CENTER (equals to 0)

Usage

There are two different ways to manage a Toast.

Calling api
import Toast from 'react-native-root-toast';


// Add a Toast on screen.
let toast = Toast.show('This is a message', {
    duration: Toast.durations.LONG,
    position: Toast.positions.BOTTOM,
    shadow: true,
    animation: true,
    hideOnPress: true,
    delay: 0,
    onShow: () => {
        // calls on toast\`s appear animation start
    },
    onShown: () => {
        // calls on toast\`s appear animation end.
    },
    onHide: () => {
        // calls on toast\`s hide animation start.
    },
    onHidden: () => {
        // calls on toast\`s hide animation end.
    }
});

// You can manually hide the Toast, or it will automatically disappear after a `duration` ms timeout.
setTimeout(function () {
    Toast.hide(toast);
}, 500);

Using a Component

NOTE: Showing a toast by using a Component inside render, The toast will be automatically disappeared when the <Toast /> is unmounted.

import React, {Component} from 'react-native';
import Toast from 'react-native-root-toast';

class Example extends Component{
    constructor() {
        super(...arguments);
        this.state = {
            visible: false
        };
    }

    componentDidMount() {
        setTimeout(() => this.setState({
            visible: true
        }), 2000); // show toast after 2s

        setTimeout(() => this.setState({
            visible: false
        }), 5000); // hide toast after 5s
    };

    render() {
        return <Toast
            visible={this.state.visible}
            position={50}
            shadow={false}
            animation={false}
            hideOnPress={true}
        >This is a message</Toast>;
    }
}

Run example:

cd ./Example
npm install

react-native-root-toast's People

Contributors

magicismight avatar

Watchers

 avatar

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.