Snackbar widget for React Native apps in Android
Java JavaScript Python
Switch branches/tags
Clone or download
Latest commit 1a9cd17 Jan 18, 2018
Permalink
Failed to load latest commit information.
Example bump example to 0.30 Jul 30, 2016
android rn 0.47 compat Jan 17, 2018
.gitignore Update ignore files Jan 25, 2016
.npmignore Update ignore files Jan 25, 2016
LICENSE mit license Nov 19, 2015
README.md cosmetics Jul 30, 2016
index.android.js Updates for React Native 0.29 compatibility (#15) Jul 30, 2016
index.ios.js Update index.ios.js Jun 15, 2016
package.json v0.1.1 Jan 17, 2018

README.md

Snackbar for React Native in Android

Expose the Snackbar android widget for react-native apps.

Snackbar demo

Snackbar provides a lightweight feedback to users about an operation, such as saving a form or deleting a message. They are similar to Toasts, but are a bit more prominent and customizable.

Fore more info please refer to the Google design spec on Snackbars.

Usage

Require it:

import Snackbar from 'react-native-android-snackbar';

Then call:

Snackbar.show('Hello World!', options);

Available options:

  • duration: one of: Snackbar.SHORT, Snackbar.LONG, Snackbar.INDEFINITE or Snackbar.UNTIL_CLICK
  • actionLabel: text to show at the right of the snackbar
  • actionColor: color of the action text in the snackbar. Like red or #FFCA00
  • actionCallback: function to be evoked after the user clicks the snackbar. Keep in mind the snackbar will automatically close just before this function call

Check full example.

To dismiss the currently active Snackbar early (for example, when changing scenes in your app), you can call:

Snackbar.dismiss();

Setup

  1. Include this module in android/settings.gradle:
include ':react-native-android-snackbar'
project(':react-native-android-snackbar').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-snackbar/android')
include ':app'
  1. Add a dependency to your app build in android/app/build.gradle:
dependencies {
   ...
   compile project(':react-native-android-snackbar')
}
  1. Change your main application to add a new package, in android/app/src/main/.../MainApplication.java:
import com.lugg.ReactSnackbar.ReactSnackbarPackage; // Add new import

public class MainApplication extends Application implements ReactApplication {
  ...
  
  @Override
  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
      new ReactSnackbarPackage() // Add the package here
    );
  }
}