Giter Site home page Giter Site logo

anu-prakash-dev / cordova-plugin-actionsheet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eddyverbruggen/cordova-plugin-actionsheet

0.0 2.0 0.0 549 KB

:clipboard: ActionSheet plugin for Cordova iOS and Android apps

Java 18.27% JavaScript 34.02% Objective-C 24.94% C# 22.77%

cordova-plugin-actionsheet's Introduction

ActionSheet Cordova / PhoneGap Plugin

by Eddy Verbruggen

0. Index

  1. Description
  2. Screenshots
  3. Installation
  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)

$ cordova plugin add cordova-plugin-actionsheet
$ cordova prepare

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

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:

<plugin name="cordova-plugin-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

show

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.

Also, wait for deviceready to fire before using plugins in general!

  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 = {
        androidTheme: window.plugins.actionsheet.ANDROID_THEMES.THEME_DEVICE_DEFAULT_LIGHT, // default is THEME_TRADITIONAL
        title: 'What do you want with this image?',
        subtitle: 'Choose wisely, my friend', // supported on iOS only
        buttonLabels: ['Share via Facebook', 'Share via Twitter'],
        androidEnableCancelButton : true, // default false
        winphoneEnableCancelButton : true, // default false
        addCancelButtonWithLabel: 'Cancel',
        addDestructiveButtonWithLabel : 'Delete it',
        position: [20, 40], // for iPad pass in the [x, y] position of the popover
        destructiveButtonLast: true // you can choose where the destructive button is shown
    };
    // 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);
  };

On iOS, you can also position the actionSheet origin by adding position: [100, 200]

hide

If for some reason you want to hide the actionsheet programmatically, do this:

  // options and callbacks are optional, so either approach will work:
  window.plugins.actionsheet.hide();
  window.plugins.actionsheet.hide({}, onSuccess, onError);

5. Credits

iOS and WP8 code: Eddy Verbruggen

Android code: mostly Brill Papping

6. Change history

  • 2.3.3 Default iPad popup is now in the center (was in the top left corner)
  • 2.3.1 Added subtitle (iOS) and destructiveButtonLast preferences. Also, iOS now uses the newer UIAlertController instead of UIActionSheet.
  • 2.2.2 OK, 2.2.1 has issues with Russian and the like, so reverted. Just add <meta charset="utf-8" /> to your html file.
  • 2.2.1 Encoding of diacritical characters fixed on iOS, so you can now use Español as a title or button label.
  • 1.1.6 You can now set the iOS actionSheet origin position (uses the iOS actionSheet.showFromRect method)
  • 1.1.2 You can now select a theme for your Android popup, see the first example above

7. 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.

cordova-plugin-actionsheet's People

Contributors

eddyverbruggen avatar pavel-durov avatar bpappin avatar ggozad avatar revolunet avatar nit23uec avatar

Watchers

James Cloos avatar Anu Prakash avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.