ActionSheet

Show a sheet of options the user can choose from.
EddyVerbruggen1.1.144
platforms: ios,android,wp8
$ cordova plugin add nl.x-services.plugins.actionsheet

ActionSheet Cordova / PhoneGap Plugin

by Eddy Verbruggen

0. Index

  1. Description
  2. Screenshots
  3. Installation
    1. Automatically (CLI / Plugman)
    2. Manually
  4. Usage
  5. Credits
  6. License

1. Description

Show a sheet of options the user can choose from.

  • Compatible with Cordova Plugman.
  • iOS uses the native UIActionSheet.
  • Android uses the native AlertDialog.
  • WP8 uses the native Popup.

2. Screenshots

iOS

   

Android

   

Windows Phone 8

   

3. Installation

Automatically (CLI / Plugman)

Compatible with Cordova Plugman, compatible with PhoneGap 3.0 CLI, here's how it works with the CLI (backup your project first!):

$ phonegap local plugin add https://github.com/EddyVerbruggen/cordova-plugin-actionsheet.git

or

$ cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-actionsheet
$ cordova prepare

ActionSheet.js is brought in automatically. There is no need to change or add anything in your html.

Manually

1. Add the following xml to your config.xml files:

iOS

<feature name="ActionSheet">
  <param name="ios-package" value="ActionSheet" />
</feature>

Android

<feature name="ActionSheet">
  <param name="android-package" value="nl.xservices.plugins.actionsheet.ActionSheet"/>
</feature>

WP8

<feature name="ActionSheet">
  <param name="wp-package" value="ActionSheet"/>
</feature>

2. Grab a copy of ActionSheet.js, add it to your project and reference it in index.html:

<script type="text/javascript" src="js/ActionSheet.js"></script>

3. Download the source files and copy them to your project.

iOS: Copy the .h and .m files to platforms/ios/<ProjectName>/Plugins

Android: Copy ActionSheet.java to platforms/android/src/nl/xservices/plugins/actionsheet/ (create the folders)

WP8: Copy ActionSheet.cs to platforms/wp8/Plugins/nl.x-services.plugins.actionsheet (create the folders)

PhoneGap Build

ActionSheet works with PhoneGap build too! Just add the following xml to your config.xml to always use the latest version of this plugin:

<gap:plugin name="nl.x-services.plugins.actionsheet" />

ActionSheet.js is brought in automatically. Make sure though you include a reference to cordova.js in your index.html's head:

<script type="text/javascript" src="cordova.js"></script>

4. Usage

Check the demo code to get you going quickly, or copy-paste some of the code below to replicate the ActionSheets of the screenshots above.

  var callback = function(buttonIndex) {
    setTimeout(function() {
      // like other Cordova plugins (prompt, confirm) the buttonIndex is 1-based (first button is index 1)
      alert('button index clicked: ' + buttonIndex);
    });
  };

  function testShareSheet() {
    var options = {
        'title': 'What do you want with this image?',
        'buttonLabels': ['Share via Facebook', 'Share via Twitter'],
        'androidEnableCancelButton' : true, // default false
        'winphoneEnableCancelButton' : true, // default false
        'addCancelButtonWithLabel': 'Cancel',
        'addDestructiveButtonWithLabel' : 'Delete it'
    };
    // Depending on the buttonIndex, you can now call shareViaFacebook or shareViaTwitter
    // of the SocialSharing plugin (https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin)
    window.plugins.actionsheet.show(options, callback);
  };

  function testDeleteSheet() {
    var options = {
        'addCancelButtonWithLabel': 'Cancel',
        'addDestructiveButtonWithLabel' : 'Delete note'
    };
    window.plugins.actionsheet.show(options, callback);
  };

  function testLogoutSheet() {
    var options = {
        'buttonLabels': ['Log out'],
        'androidEnableCancelButton' : true, // default false
        'winphoneEnableCancelButton' : true, // default false
        'addCancelButtonWithLabel': 'Cancel'
    };
    window.plugins.actionsheet.show(options, callback);
  };

5. Credits

iOS and WP8 code: Eddy Verbruggen

Android code: Brill Papping

6. License

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.