Code Monkey home page Code Monkey logo

cordova-pickerview's Introduction

Cordova PickerView Plugin

by Olivier Louvignes

DESCRIPTION

  • This plugin provides a simple way to use the UIPickerView native component from iOS.

  • This plugin is built for Cordova >= v2.1.0 with ARC.

  • There is a Sencha Touch 2.0 plugin to easily leverage this plugin here

Screenshot

SAMPLE PROJECT GENERATION

You can generate a sample XCode project by running samples/ios/create.sh from the root of the repository. You will have to manually add the ActionSheet folder to Xcode (see step 2).

PLUGIN SETUP FOR IOS

Using this plugin requires Cordova iOS.

  1. Make sure your Xcode project has been updated for Cordova

  2. Rename the src/ios folder to PickerView, drag and drop it from Finder to your Plugins folder in XCode, using "Create groups for any added folders"

  3. Add the .js files to your www folder on disk, and add reference(s) to the .js files using <script> tags in your html file(s)

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

  4. Add new entry with key PickerView and value PickerView to Plugins in Cordova.plist/Cordova.plist

JAVASCRIPT INTERFACE (IOS/ANDROID)

// After device ready, create a local alias
var pickerView = window.plugins.pickerView;

// Basic with title & defaultValue selected
var slots = [
    {name: 'foo', value: 'baz', data: [
        {value: 'foo', text: 'Displayed Foo'},
        {value: 'bar', text: 'Displayed Bar'},
        {value: 'baz', text: 'Displayed Baz'}
    ]}
];
/*pickerView.create('Title', slots, function(selectedValues, buttonIndex) {
    console.warn('create(), arguments=' + Array.prototype.slice.call(arguments).join(', '));
});*/

// Complex example with 2 slots
var slots = [
    {name : 'limit_speed', title: 'Speed', width: 140, data : [
        {text: '50 KB/s', value: 50},
        {text: '100 KB/s', value: 100},
        {text: '200 KB/s', value: 200},
        {text: '300 KB/s', value: 300}
    ]},
    {name : 'road_type', title: 'Road', width: 160, data : [
        {text: 'Highway', value: 50},
        {text: 'Town', value: 100},
        {text: 'City', value: 200}
    ]}
];
pickerView.create('', slots, function(selectedValues, buttonIndex) {
    console.warn('create(), arguments=' + Array.prototype.slice.call(arguments).join(', '));
}, {style: 'black-opaque', doneButtonLabel: 'OK', cancelButtonLabel: 'Annuler', sourceRect: [100.0, 100.0, 20.0, 20.0], arrowDirection: 'up'});

// Set values after create
setTimeout(function() {
    pickerView.setValue({limit_speed: 100, road_type: 200}, {animated: true});
}, 1000);
  • Check source for additional configuration.

BUGS AND CONTRIBUTIONS

Patches welcome! Send a pull request. Since this is not a part of Cordova Core (which requires a CLA), this should be easier.

Post issues on Github

The latest code (my fork) will always be here

LICENSE

The MIT License

Copyright (c) 2012 Olivier Louvignes

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.

CREDITS

Contributors :

Inspired by :

cordova-pickerview's People

Contributors

coladarci avatar mgcrea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cordova-pickerview's Issues

Thanks!

Thanks for the updates. Using it in one of my projects. Thanks!

Compatibility for iOS8

The PickerView is not compatible with iOS8. It displays a white empty selector when the PickerView got created.

landscape on iPad

Even if I've disabled both landscape orientations in xcode, the location of the pickerview changes on the ipad depending on whether or not the ipad is rotated or not.

Picker Viewer: Title and Options

I have followed the step-by-step instructions. Using Cordova 2.2.0, ios 6.1.

Using the given examples:
(i)using complex example - picker scrolls up but slots are empty. I.e No options.
(ii)using simple example - application breaks - after investigation i realised that setting a title it breaks.
(iii)using simple example - no breaks. same as (i)

Screenshot:
iOS Simulator Screen shot 14 Feb 2013 10 27 29

Cannot install the plugin

$ cordova plugin add org.apache.cordova.plugins.PickerView
Fetching plugin "org.apache.cordova.plugins.PickerView" via plugin registry
npm http GET http://registry.cordova.io/org.apache.cordova.plugins.PickerView
npm http 404 http://registry.cordova.io/org.apache.cordova.plugins.PickerView
$ cordova plugin add https://github.com/mgcrea/cordova-pickerview.git
Fetching plugin "https://github.com/mgcrea/cordova-pickerview.git" via git clone
Installing "org.apache.cordova.plugins.PickerView" for android
Error during processing of action! Attempting to revert...
Failed to install 'org.apache.cordova.plugins.PickerView':Error: Uh oh!
"/Users/zabojad/my_wksp/cordova/plugins/org.apache.cordova.plugins.PickerView/src/android/PickerView.java" not found!
    at Object.module.exports.common.copyFile (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/platforms/common.js:38:40)
    at Object.module.exports.common.copyNewFile (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/platforms/common.js:69:16)
    at module.exports.source-file.install (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/platforms/android.js:78:20)
    at Object.ActionStack.process (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/util/action-stack.js:67:25)
    at handleInstall (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:575:20)
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:335:28
    at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:787:54)
    at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:816:30)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:749:13)
    at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:509:49
Error: Uh oh!
"/Users/zabojad/my_wksp/cordova/plugins/org.apache.cordova.plugins.PickerView/src/android/PickerView.java" not found!
    at Object.module.exports.common.copyFile (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/platforms/common.js:38:40)
    at Object.module.exports.common.copyNewFile (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/platforms/common.js:69:16)
    at module.exports.source-file.install (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/platforms/android.js:78:20)
    at Object.ActionStack.process (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/util/action-stack.js:67:25)
    at handleInstall (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:575:20)
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:335:28
    at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:787:54)
    at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:816:30)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:749:13)
    at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:509:49

Crashes on latest IOS 7

I use this plugin in my application and tested it on IPhone 4, IPhone 4S, IPhone 5 and had no problems with this plugin.

But when I tested it on a IPhone with the latest IOS7 release the Pickerview crashes my application after pressing "done".

issue & comment with setValue method

Issue:

Animation cannot be set to false. There is a value for it but changing it doesn't do anything.

Comment:

Probably should mention in the docs, that (I think) setValue should be called after the create function?

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.