Skip to content
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ context
| albums | null | Albums from where the images are picked. |


### Image properties

Once image is picked some options can be applied to it before it is used:

| Option | Default | Description |
| --- | --- | --- |
| maxWidth | null | Image max width |
| maxHeight | null | Image max height |
| aspectRatio | fit | iOS only. Possible values are `fit` and `fill`. [Read more](https://developer.apple.com/documentation/photos/phimagecontentmode) |

## License

2015, Telerik AD
16 changes: 13 additions & 3 deletions demo/app/main-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ import { isAndroid } from "tns-core-modules/platform";
import * as imagepicker from "nativescript-imagepicker";

let list;
let imageSrc;

export function pageLoaded(args: EventData) {
let page = <Page>args.object;
list = page.getViewById("urls-list");
imageSrc = page.getViewById("imageSrc");
}

export function onSelectMultipleTap(args) {
let context = imagepicker.create({ mode: "multiple" });
startSelection(context);
startSelection(context, false);
}

export function onSelectSingleTap(args) {
let context = imagepicker.create({ mode: "single" });
startSelection(context);
startSelection(context, true);
}

function startSelection(context) {
function startSelection(context, isSingle) {
context
.authorize()
.then(function() {
Expand All @@ -32,6 +34,14 @@ function startSelection(context) {
selection.forEach(function(selected) {
console.log("----------------");
console.log("uri: " + selected.uri);
if (isSingle) {
selected.getImage({ maxWidth: 200, maxHeight: 200, aspectRatio: 'fill' })
.then((imageSource) => {
imageSrc.src = imageSource;
});
} else {
imageSrc.visibility = 'hidden';
}
});
list.items = selection;
}).catch(function (e) {
Expand Down
2 changes: 2 additions & 0 deletions demo/app/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
</GridLayout>
</ListView.itemTemplate>
</ListView>

<Image id="imageSrc" width="200" height="200" />
<Button row="1" text="Pick Single" tap="onSelectSingleTap" horizontalAlignment="center" />
<Button row="2" text="Pick Multiple" tap="onSelectMultipleTap" horizontalAlignment="center" />
</GridLayout>
Expand Down
4 changes: 3 additions & 1 deletion src/imagepicker.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const IMAGE_HEIGHT = 80;
interface ImageOptions {
maxWidth?: number;
maxHeight?: number;
aspectRatio?: "fill" | "fit";
}

export function create(options?): ImagePicker {
Expand Down Expand Up @@ -344,6 +345,7 @@ class ImagePickerPH extends ImagePicker {
return new Promise<image_source.ImageSource>((resolve, reject) => {
let size: CGSize = options ? CGSizeMake(options.maxWidth, options.maxHeight) : PHImageManagerMaximumSize;
let resizeMode = PHImageRequestOptions.alloc().init();
let aspectRatio = (options && options.aspectRatio && options.aspectRatio === 'fill') ? PHImageContentMode.AspectFill : PHImageContentMode.AspectFit;

// TODO: Decide whether it is benefical to use PHImageRequestOptionsResizeModeFast
// Accuracy vs Performance. It is probably best to expose these as iOS specific options.
Expand All @@ -357,7 +359,7 @@ class ImagePickerPH extends ImagePicker {
PHImageManager.defaultManager().requestImageForAssetTargetSizeContentModeOptionsResultHandler(
image,
size,
PHImageContentMode.AspectFit, // Scales the image so that its larger dimension fits the target size
aspectRatio,
resizeMode,
(createdImage, data) => {
if (createdImage) {
Expand Down
5 changes: 5 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export interface ImageOptions {
* The maximum height that the image is allowed to be.
*/
maxHeight?: number;

/**
* iOS only. The image aspect ratio. Default value: fit.
*/
aspectRatio?: "fill" | "fit";
}

export class SelectedAsset extends imageAssetModule.ImageAsset {
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-imagepicker",
"version": "3.0.7",
"version": "4.0.0",
"description": "A plugin for the NativeScript framework implementing multiple image picker",
"repository": {
"type": "git",
Expand Down