angjelkom / cordova-plugin-snackbar

Cordova Plugin that displays a Material Design Snackbar
Apache License 2.0
9 stars 7 forks source link

cordova-plugin-snackbar

Changelog 2.2.0:

NOTE:

Use cordova.plugins.snackbar.create(text, duration, button, callback); instead of the previous cordova.plugin.snackbar(text, duration, button, callback);

Use cordova.plugins.snackbar.close(callback); to close the snackbar

MAJOR UPDATE Version 2.1.4:

This Update removes the need to manually modify the AndroidManifest.xml file to modify the App theme, the plugin will do that for you.

NOTE: You need to have Cordova 6.3.1 or higher to be able to do the modification automatically

Installation

Before:

android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
  <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
      <intent-filter android:label="@string/launcher_name">
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
  </activity>

After:

android:theme="@style/Theme.AppCompat.NoActionBar"
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar" android:windowSoftInputMode="adjustResize">
    <intent-filter android:label="@string/launcher_name">
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Usage

//Creates one snackbar at time;

cordova.plugins.snackbar.create(text, duration, button, callback);

text // String text for the Snackbar

duration  //How long to show the Snackbar
parameters: "SHORT", "LONG" and "INDEFINITE" (default, show snackbar until it's dismissed by clicking the action button)

button - String text for the Action Button

callback - Callback function for the Action Button.

//Close snackbar programatically

cordova.plugins.snackbar.close(callback);

callback - Success Callback function when the snackbar closes.

Example

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    cordova.plugins.snackbar.create('This is a indefinite snackbar text', 'INDEFINITE', "Dismiss", function(){
      console.log('Dismiss Button Clicked!');
    });

    cordova.plugins.snackbar.close(function(){
      console.log('Snackbar Closed Programmatically!');
    });
}

Supported Platforms

Screenshot