Skip to content

Comply with verified plugin definition #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
# Output
dist

# Dev dependencies
node_modules

# Source, written in TypeScript so JavaScript is not necessary
nativescript-imagepicker/**/*.js
nativescript-imagepicker/**/*.js.map

# Example platforms
/examples/ExampleImgPick/platforms/
/examples/ExampleImgPick/lib/
/examples/ExampleImgPickNG/platforms/
/examples/ExampleImgPickNG/lib/
/examples/ExampleImgPickNG/**/*.js
/examples/ExampleImgPickNG/**/*.js.map
.vscode
.idea
.DS_Store
*.js
*.js.map
*.log
!src/scripts/*.js
!seed-tests/*.js
seed-tests/seed-copy/**/*.*
seed-tests/seed-copy-new-git-repo/**/*.*
demo/app/*.js
!demo/karma.conf.js
!demo/app/tests/*.js
demo/*.d.ts
!demo/references.d.ts
demo/lib
demo/platforms
demo/node_modules
demo-angular/app/*.js
!demo-angular/karma.conf.js
!demo-angular/app/tests/*.js
demo-angular/*.d.ts
!demo-angular/references.d.ts
demo-angular/lib
demo-angular/platforms
demo-angular/node_modules
node_modules
publish/src
publish/package
demo/report/report.html
demo/report/stats.json
demo-angular/report/report.html
demo-angular/report/stats.json
64 changes: 64 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
matrix:
include:
- stage: "Lint"
language: node_js
os: linux
node_js: "6"
script: cd src && npm run ci.tslint && cd ../demo && npm run ci.tslint && cd ../demo-angular && npm run ci.tslint
- stage: "WebPack"
os: osx
env:
- Platform="iOS"
osx_image: xcode8.3
language: node_js
node_js: "6"
jdk: oraclejdk8
script: cd demo && npm run build.plugin && npm i && npm run build-ios-bundle && cd ../demo-angular && npm run build.plugin && npm i && npm run build-ios-bundle
- language: android
os: linux
env:
- Platform="Android"
jdk: oraclejdk8
before_install: nvm install 6.10.3
script: cd demo && npm run build.plugin && npm i && npm run build-android-bundle && cd ../demo-angular && npm run build.plugin && npm i && npm run build-android-bundle
- stage: "Build"
env:
- Android="25"
language: android
os: linux
jdk: oraclejdk8
before_install: nvm install 6.10.3
script: cd demo && npm run ci.android.build && cd ../demo-angular && npm run ci.android.build
- os: osx
env:
- iOS="10.3"
- Xcode="8.3"
osx_image: xcode8.3
language: node_js
node_js: "6"
jdk: oraclejdk8
script: cd demo && npm run ci.ios.build && cd ../demo-angular && npm run ci.ios.build

android:
components:
- tools
- platform-tools
- build-tools-25.0.2
- android-25
- extra-android-m2repository

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock

cache:
directories:
- .nvm
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/

install:
- echo no | npm install -g nativescript
- tns usage-reporting disable
- tns error-reporting disable


115 changes: 99 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,107 @@
# Image Picker for the NativeScript framework
An image picker control that supports multiple selection.
# NativeScript Image Picker ![apple](https://cdn3.iconfinder.com/data/icons/picons-social/57/16-apple-32.png) ![android](https://cdn4.iconfinder.com/data/icons/logos-3/228/android-32.png)

## Usage
[Please check the following article.](nativescript-imagepicker/README.md)

### Prerequisites
- [nodejs](https://nodejs.org/)
- [nativescript](https://www.nativescript.org/)
[![npm](https://img.shields.io/npm/v/nativescript-imagepicker.svg)](https://www.npmjs.com/package/nativescript-imagepicker)
[![npm](https://img.shields.io/npm/dm/nativescript-imagepicker.svg)](https://www.npmjs.com/package/nativescript-imagepicker)
[![Build Status](https://travis-ci.org/NativeScript/nativescript-imagepicker.svg?branch=master)](https://travis-ci.org/NativeScript/nativescript-imagepicker)

Imagepicker plugin supporting both single and multiple selection.
<br />Plugin supports **iOS8+** and uses [Photos Framework](https://developer.apple.com/library/prerelease/ios//documentation/Photos/Reference/Photos_Framework/index.html).
<br />For **Android** it uses Intents to open the stock images or file pickers. For Android 6 (API 23) and above the permissions to read file storage should be explicitly required. See demo for implementation details.

## Installation

In Command prompt / Terminal navigate to your application root folder and run:

## Development
Go to `nativescript-imagepicker`:
```
npm link
```
Go to `examples\ExampleImgPick`:
tns plugin add <your-plugin-name>
```
npm link nativescript-imagepicker

## Usage

The best way to explore the usage of the plugin is to inspect both demo apps in the plugin repository.
In `demo` folder you can find the usage of the plugin for TypeScript non-Angular application. Refer to `demo/app/main-page.ts`.
In `demo-angular` is the usage in an Angular app. Refer to `demo-angular/app/app.component.ts`.

In addition to the plugin usage, both apps are webpack configured.

In short here are the steps:

### Import the plugin

*TypeScript*
```
import * as imagepicker from "nativescript-imagepicker";
```
Then you can run the app using either:

*Javascript*
```
var imagepicker = require("nativescript-imagepicker");
```
tns run ios
tns run android

### Create imagepicker

Create imagepicker in `single` or `multiple` mode to specifiy if the imagepicker will be used for single or multiple selection of images

*TypeScript*
```
let context = imagepicker.create({
mode: "single" // use "multiple" for multiple selection
});
````

*Javascript*
````
var context = imagepicker.create({ mode: "single" }); // use "multiple" for multiple selection
````

### Request permissions, show the images list and process the selection

```
context
.authorize()
.then(function() {
return context.present();
})
.then(function(selection) {
selection.forEach(function(selected) {
// process the selected image
});
list.items = selection;
}).catch(function (e) {
// process error
});
```

> **NOTE**: To request permissions for Android 6+ (API 23+) we use [nativescript-permissions](https://www.npmjs.com/package/nativescript-permissions).

## API

### Methods

* create(options) - creates instance of the imagepicker. Possible options are:

| Option | Platform | Default | Description |
| --- | --- | --- | --- |
| mode | both | multiple | The mode if the imagepicker. Possible values are `single` for single selection and `multiple` for multiple selection. |
| doneText | iOS | Done | The text of the "Done" button on top right. |
| cancelText | iOS | Cancel | The text of the "Cancel" button on top left. |
| albumsText | iOS | Albums | The title of the "Albums" screen from where the selection of album and images can be done. |
| newestFirst | iOS | false | Set to `true` to sort the images in an album by newest first. |

* authorize() - request iOS specific permissions.
* present() - show the albums to present the user the ability to select images. Returns an array of the selected images.
* cancel() - cancel selection. iOS only.
* done() - confirm the selection is ready. iOS only.


### Properties
| Property | Default | Description |
| --- | --- | --- |
| selection | null | An array of selected image assets. |
| albums | null | Albums from where the images are picked. |


## License

2015, Telerik AD
16 changes: 16 additions & 0 deletions demo-angular/app/App_Resources/Android/app.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Add your native dependencies here:

// Uncomment to add recyclerview-v7 dependency
//dependencies {
// compile 'com.android.support:recyclerview-v7:+'
//}

android {
defaultConfig {
generatedDensities = []
applicationId = "org.nativescript.imagepickerdemoangular"
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// You can add custom settings here
// for example you can uncomment the following line to force distribution code signing
// CODE_SIGN_IDENTITY = iPhone Distribution
// To build for device with XCode 8 you need to specify your development team. More info: https://developer.apple.com/library/prerelease/content/releasenotes/DeveloperTools/RN-Xcode/Introduction.html
// DEVELOPMENT_TEAM = YOUR_TEAM_ID;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ScrollView>
<StackLayout>
<GridLayout height="94" columns="94, *" rows="*, *" *ngFor="let item of items">
<Image rowSpan="2" width="94" height="94" [src]="item.thumb"></Image>
<Image rowSpan="2" width="94" height="94" [src]="item"></Image>
<Label col="1" [text]="item.uri"></Label>
<Label col="1" row="1" [text]="item.fileUri"></Label>
</GridLayout>
Expand Down
53 changes: 53 additions & 0 deletions demo-angular/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Component, ChangeDetectorRef } from "@angular/core";
import { ListView } from "tns-core-modules/ui/list-view";
import { isAndroid } from "tns-core-modules/platform";
import * as imagepicker from "nativescript-imagepicker";

@Component({
selector: "my-app",
templateUrl: "app.component.html",
})
export class AppComponent {

items = [];

constructor(private _changeDetectionRef: ChangeDetectorRef) {
}

onSelectMultipleTap() {
let context = imagepicker.create({
mode: "multiple"
});
this.startSelection(context);
}

onSelectSingleTap() {
let context = imagepicker.create({
mode: "single"
});
this.startSelection(context);
}

startSelection(context) {
let _that = this;

context
.authorize()
.then(() => {
_that.items = [];
return context.present();
})
.then((selection) => {
console.log("Selection done:");
selection.forEach(function (selected) {
console.log("----------------");
console.log("uri: " + selected.uri);
console.log("fileUri: " + selected.fileUri);
});
_that.items = selection;
_that._changeDetectionRef.detectChanges();
}).catch(function (e) {
console.log(e);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import '~/css/core.light.css';
@import '~/css/core.light.css';

button, label, stack-layout {
horizontal-align: center;
horizontal-align: center;
}

button {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"v8Flags": "--expose_gc"
},
"main": "main.js",
"name": "tns-template-hello-world-ng",
"version": "3.0.0-rc.1"
"name": "tns-template-hello-world",
"version": "3.1.0"
}
12 changes: 12 additions & 0 deletions demo-angular/app/tests/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// var ImagePicker = require("nativescript-imagepicker").ImagePicker;
// var imagePicker = new ImagePicker();

// describe("greet function", function() {
// it("exists", function() {
// expect(yourPlugin.greet).toBeDefined();
// });

// it("returns a string", function() {
// expect(yourPlugin.greet()).toEqual("Hello, NS");
// });
// });
9 changes: 9 additions & 0 deletions demo-angular/app/vendor-platform.android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require("application");
if (!global["__snapshot"]) {
/*
In case snapshot generation is enabled these modules will get into the bundle but will not be required/evaluated.
The snapshot webpack plugin will add them to the tns-java-classes.js bundle file. This way, they will be evaluated on app start as early as possible.
*/
require("ui/frame");
require("ui/frame/activity");
}
File renamed without changes.
Loading