Snackbar widget for React Native apps in Android
Java JavaScript
Pull request Compare This branch is 21 commits behind luggit:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Example
android
.gitignore
LICENSE
README.md
index.android.js
index.ios.js
package.json

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:

var Snackbar = require('react-native-android-snackbar');

Then call:

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

Available options:

  • duration: one of: Snackbar.SHORT, Snackbar.LONG 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.

Setup

  1. Include this module in android/settings.gradle:

    include ':react-native-android-snackbar'
    include ':app'
    
    project(':react-native-android-snackbar').projectDir = new File(rootProject.projectDir,
      '../node_modules/react-native-android-snackbar/android')
    
  2. Add a dependency to your app build in android/app/build.gradle:

    dependencies {
        ...
        compile project(':react-native-android-snackbar')
    }
    
  3. Change your main activity to add a new package, in android/app/src/main/.../MainActivity.java:

    import com.lugg.ReactSnackbar.ReactSnackbarPackage; // Add new import
    
    public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
    
        private ReactInstanceManager mReactInstanceManager;
        private ReactRootView mReactRootView;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            mReactRootView = new ReactRootView(this);
    
            mReactInstanceManager = ReactInstanceManager.builder()
                    .setApplication(getApplication())
                    .setBundleAssetName("index.android.bundle")
                    .setJSMainModuleName("index.android")
                    .addPackage(new MainReactPackage())
                    .addPackage(new ReactSnackbarPackage(mReactRootView)) // add the package here
                    .setUseDeveloperSupport(BuildConfig.DEBUG)
                    .setInitialLifecycleState(LifecycleState.RESUMED)
                    .build();