nativescript-imagepicker
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -8,3 +8,3 @@ { | ||
"name": "nativescript-imagepicker", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"nativescript": { | ||
@@ -11,0 +11,0 @@ "platforms": { |
112
README.md
@@ -10,23 +10,115 @@ # Image Picker for the NativeScript framework | ||
- [Issues](https://github.com/NativeScript/nativescript-imagepicker/issues) | ||
- [Example](https://github.com/NativeScript/nativescript-imagepicker/tree/release/examples/ExampleImgPick/app) | ||
# How-to Pick Multiple Images | ||
Examples: | ||
- [Select and Upload](https://github.com/NativeScript/sample-ImageUpload) | ||
- [imagepicker](https://github.com/NativeScript/nativescript-imagepicker/tree/release/examples/ExampleImgPick/app) | ||
## Installation | ||
### Install plugin using NativeScript CLI | ||
From the command prompt go to your app's root folder and execute: | ||
``` | ||
var imagepicker = require("nativescript-imagepicker"); | ||
tns plugin add nativescript-imagepicker | ||
``` | ||
### Install plugin using AppBuilder CLI | ||
``` | ||
appbuilder plugin add nativescript-imagepicker | ||
``` | ||
### Install plugin using AppBuilder IDE | ||
In the Project Navigator, right click your project and choose Manage Packages. | ||
Choose the Plugins Marketplace tab. | ||
Search or browse for a plugin and click Install. | ||
## Usage | ||
For sample application with single and multiple image selection ready for Android and IOS | ||
[follow this link](https://github.com/NativeScript/sample-ImageUpload) | ||
### How-to Pick Multiple Images | ||
``` | ||
var imagepickerModule = require("nativescript-imagepicker"); | ||
function selectImages() { | ||
var context = imagepicker.create({ | ||
var context = imagepicker.create({ | ||
mode: "multiple" | ||
}); | ||
context | ||
.authorize() | ||
.then(function() { | ||
return context.present(); | ||
}) | ||
.then(function(selection) { | ||
console.log("Selection done:"); | ||
selection.forEach(function(selected) { | ||
console.log(" - " + selected.uri); | ||
}); | ||
}).catch(function (e) { | ||
console.log(e); | ||
}); | ||
} | ||
``` | ||
### How-to Pick Single Image | ||
``` | ||
var context = imagepicker.create({ | ||
mode: "single" | ||
}); | ||
``` | ||
### How-to Bind Selected Images | ||
#### main-page.xml | ||
``` | ||
<ListView id="urls-list"> | ||
<ListView.itemTemplate> | ||
<GridLayout columns="100, auto" rows="*, *, *"> | ||
<Image rowSpan="3" width="100" height="100" src="{{ thumb }}" /> | ||
<Label col="1" row="0" text="{{ uri }}" textWrap="true"/> | ||
<Label col="1" row="2" text="{{ fileUri }}" /> | ||
</GridLayout> | ||
</ListView.itemTemplate> | ||
</ListView> | ||
<Button row="1" text="Pick Multiple Images" tap="onSelectMultipleTap" /> | ||
<Button row="2" text="Pick Single Image" tap="onSelectSingleTap" /> | ||
``` | ||
#### main-page.js | ||
``` | ||
var imagepickerModule = require("nativescript-imagepicker"); | ||
var page; | ||
var list; | ||
function pageLoaded(args) { | ||
page = args.object; | ||
list = page.getViewById("urls-list"); | ||
} | ||
function onSelectMultipleTap(args) { | ||
var context = imagepickerModule.create({ | ||
mode: "multiple" | ||
}); | ||
startSelection(context); | ||
} | ||
function onSelectSingleTap(args) { | ||
var context = imagepickerModule.create({ | ||
mode: "single" | ||
}); | ||
startSelection(context); | ||
} | ||
function startSelection(context) { | ||
context | ||
.authorize() | ||
.then(function() { | ||
list.items = []; | ||
return context.present(); | ||
}) | ||
.then(function(selection) { | ||
console.log("Selection done:"); | ||
selection.forEach(function(selected) { | ||
console.log(" - " + selected.uri); | ||
console.log("uri: " + selected.uri); | ||
console.log("fileUri: " + selected.fileUri); | ||
}); | ||
list.items = selection; | ||
}).catch(function (e) { | ||
@@ -36,2 +128,6 @@ console.log(e); | ||
} | ||
``` | ||
exports.pageLoaded = pageLoaded; | ||
exports.onSelectMultipleTap = onSelectMultipleTap; | ||
exports.onSelectSingleTap = onSelectSingleTap; | ||
``` |
37361
131