/react-native-snackbar

Material-design "Snackbar" component for both Android and iOS.

Primary LanguageObjective-CMIT LicenseMIT

react-native-snackbar

npm downloads npm version Latest GitHub tag

Material-design "Snackbar" component for both Android and iOS.

See Google Design for more info on Snackbars.

Installation

To use this extension, you have to do the following steps:

  1. In your react-native project, run

    • using npm:

      npm install react-native-snackbar
    • using yarn:

      yarn add react-native-snackbar
  2. Link the library using react-native link react-native-snackbar (learn more about linking.

  3. Import it in your JS where you want to show a snackbar:

    import Snackbar from 'react-native-snackbar';

Usage

To show a simple snackbar:

Snackbar.show({
    title: 'Hello world',

    // Optional duration. Can be one of LENGTH_LONG | LENGTH_SHORT | LENGTH_INDEFINITE.
    duration: Snackbar.LENGTH_LONG,
});

Or, to include an action button:

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

TODO: Add screenshots 😎

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 (e.g. com.android.tools.build:gradle:2.2.2). You should also be using the latest compileSdkVersion (e.g. 25) and buildToolsVersion (e.g. 25.0.2). See #2 for more info.