Git Product home page Git Product logo

react-native-snackbar's Introduction

React Native Snackbar

Build status npm downloads npm version Latest GitHub tag

Material-design "Snackbar" component for Android and iOS:

Snackbar screenshot

Snackbars are used for displaying a brief message to the user, along with an optional action. They animate up from the bottom of the screen and then disappear shortly afterward.

See Google's Material Design guidelines for more info on Snackbars and when to use them.

How it works

Snackbar.show({
    title: 'Hello world',
    duration: Snackbar.LENGTH_SHORT,
});

Or, to include an action button:

Snackbar.show({
    title: 'Hello world',
    duration: Snackbar.LENGTH_INDEFINITE,
    action: {
        title: 'UNDO',
        color: 'green',
        onPress: () => { /* Do something. */ },
    },
});

Installation

  1. Install:

    • Using npm: npm install react-native-snackbar --save
    • Using Yarn: yarn add react-native-snackbar
  2. Link:

    • react-native link react-native-snackbar
    • Or if that fails, link manually using these steps
  3. Import it in your JS:

    import Snackbar from 'react-native-snackbar';

Customization

Snackbar.show() accepts the following options:

Key Data type Default value? Description
title string Required. The message to show.
duration See below Snackbar.LENGTH_SHORT How long to display the Snackbar.
action object (described below) undefined (no button) Optional config for the action button (described below).
backgroundColor string or style undefined (natively renders as black) The background color for the whole Snackbar.

Where duration can be one of the following (timing may vary based on device):

  • Snackbar.LENGTH_SHORT (just over a second)
  • Snackbar.LENGTH_LONG (about three seconds)
  • Snackbar.LENGTH_INDEFINITE (stays on screen until the button is pressed)

And the optional action object can contain the following options:

Key Data type Default value? Description
title string Required. The text to show on the button.
onPress function undefined (Snackbar is simply dismissed) A callback for when the user taps the button.
color string or style undefined (natively renders as white) The text color for the button.

Notes

A few people have suggested that the default Gradle configs created by react-native init are too outdated. If you have issues compiling for Android after linking this library, please try upgrading Gradle to the latest version! For example:

In your android/build.gradle:

  • com.android.tools.build:gradle:2.2.2

In your android/app/build.gradle:

  • compileSdkVersion 25
  • buildToolsVersion "25.0.2"

react-native-snackbar's People

Contributors

abrahambotros avatar ahanriat avatar bhullnatik avatar brunolemos avatar cooperka avatar dantman avatar gregoiredumas avatar iroachie avatar jazz747 avatar remstos avatar sandromachado avatar testauthbasic avatar

Watchers

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