From 6f39deb069b85b628c90d7758e33961f8ee82898 Mon Sep 17 00:00:00 2001 From: Veselina Radeva Date: Fri, 6 Oct 2017 17:56:23 +0300 Subject: [PATCH 1/4] (feat): Add option for iOS image aspect ration. Default is `fill`. --- README.md | 10 ++++++++++ demo/app/main-page.ts | 16 +++++++++++++--- demo/app/main-page.xml | 2 ++ src/imagepicker.ios.ts | 4 +++- src/index.d.ts | 5 +++++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9e541de..b6c04f9 100644 --- a/README.md +++ b/README.md @@ -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 | +| iosAspectRatio | fill | iOS only. Possible values are `fit` and `fill`. [Read more](https://developer.apple.com/documentation/photos/phimagecontentmode) | + ## License 2015, Telerik AD \ No newline at end of file diff --git a/demo/app/main-page.ts b/demo/app/main-page.ts index 6b2ec52..1880027 100644 --- a/demo/app/main-page.ts +++ b/demo/app/main-page.ts @@ -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 = 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() { @@ -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, iosAspectRatio: 'fit' }) + .then((imageSource) => { + imageSrc.src = imageSource; + }); + } else { + imageSrc.visibility = 'hidden'; + } }); list.items = selection; }).catch(function (e) { diff --git a/demo/app/main-page.xml b/demo/app/main-page.xml index b73788a..41d50bb 100644 --- a/demo/app/main-page.xml +++ b/demo/app/main-page.xml @@ -12,6 +12,8 @@ + +