Socket
Socket
Sign inDemoInstall

nativescript-imagepicker

Package Overview
Dependencies
31
Maintainers
3
Versions
38
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.4.1 to 2.5.0

4

albums.ios.js

@@ -75,4 +75,4 @@ "use strict";

"<GridLayout rows=\"*, *\" columns=\"auto, *\" backgroundCount=\"red\">" +
"<Image rowSpan=\"2\" imageSource=\"{{ thumb }}\" width=\"80\" height=\"80\" margin=\"2\" />" +
"<Label row=\"0\" col=\"1\" text=\"{{ title }}\" verticalAlignment=\"bottom\" fontSize=\"16\" margin=\"0 12\" />" +
"<Image rowSpan=\"2\" src=\"{{ thumbAsset }}\" width=\"80\" height=\"80\" margin=\"2\" />" +
"<Label row=\"0\" col=\"1\" text=\"{{ title}}\" verticalAlignment=\"bottom\" fontSize=\"16\" margin=\"0 12\" />" +
"<Label row=\"1\" col=\"1\" text=\"{{ assets.length }}\" verticalAlignment=\"top\" fontSize=\"13\" margin=\"0 12\" />" +

@@ -79,0 +79,0 @@ "</GridLayout>";

@@ -97,4 +97,4 @@ // Apple example: https://developer.apple.com/library/ios/samplecode/UsingPhotosFramework/Listings/SamplePhotosApp_AAPLRootListViewController_m.html

"<GridLayout rows=\"*, *\" columns=\"auto, *\" backgroundCount=\"red\">" +
"<Image rowSpan=\"2\" imageSource=\"{{ thumb }}\" width=\"80\" height=\"80\" margin=\"2\" />" +
"<Label row=\"0\" col=\"1\" text=\"{{ title }}\" verticalAlignment=\"bottom\" fontSize=\"16\" margin=\"0 12\" />" +
"<Image rowSpan=\"2\" src=\"{{ thumbAsset }}\" width=\"80\" height=\"80\" margin=\"2\" />" +
"<Label row=\"0\" col=\"1\" text=\"{{ title}}\" verticalAlignment=\"bottom\" fontSize=\"16\" margin=\"0 12\" />" +
"<Label row=\"1\" col=\"1\" text=\"{{ assets.length }}\" verticalAlignment=\"top\" fontSize=\"13\" margin=\"0 12\" />" +

@@ -101,0 +101,0 @@ "</GridLayout>";

@@ -18,4 +18,2 @@ "use strict";

var currentPageWidth = platform.screen.mainScreen.heightDIPs;
console.log(currentPageWidth);
console.log(currentPageWidth);
list.listViewLayout.spanCount = Math.floor(currentPageWidth / 80);

@@ -42,4 +40,6 @@ });

var item = new action_bar_1.ActionItem();
item.bind({ targetProperty: "text", sourceProperty: "imagePicker.selection.length", twoWay: false,
expression: "imagePicker.doneText + (imagePicker.mode === 'single' ? '' : ' (' + imagePicker.selection.length + ')')" });
item.bind({
targetProperty: "text", sourceProperty: "imagePicker.selection.length", twoWay: false,
expression: "imagePicker.doneText + (imagePicker.mode === 'single' ? '' : ' (' + imagePicker.selection.length + ')')"
});
item.ios.position = "right";

@@ -59,6 +59,3 @@ item.on(action_bar_1.ActionItem.tapEvent, done);

"<GridLayout margin=\"1\" rows=\"auto\" tap=\"{{ toggleSelection }}\">" +
"<Image height=\"78\" width=\"78\" opacity=\"{{ selected ? 0.7 : 1 }}\" imageSource=\"{{ thumb }}\"/>" +
"<Border opacity=\"{{ selected ? 1 : 0 }}\" width=\"24\" height=\"24\" margin=\"2\" horizontalAlignment=\"right\"" +
"verticalAlignment=\"bottom\" borderWidth=\"1\" borderColor=\"white\" backgroundColor=\"blue\"" +
"borderRadius=\"12\"/>" +
"<Image height=\"78\" width=\"78\" opacity=\"{{ selected ? 0.7 : 1 }}\" src=\"{{ $value }}\"/>" +
"</GridLayout>";

@@ -65,0 +62,0 @@ page.content = listView;

@@ -19,9 +19,7 @@ import application = require("application");

// Get the current Size, and then adjust the number of columns based on it...
list.listViewLayout.spanCount = Math.floor(platform.screen.mainScreen.widthDIPs/80);
list.listViewLayout.spanCount = Math.floor(platform.screen.mainScreen.widthDIPs / 80);
application.on("orientationChanged", function(e:application.OrientationChangedEventData){
var currentPageWidth = platform.screen.mainScreen.heightDIPs
console.log(currentPageWidth);
console.log(currentPageWidth);
list.listViewLayout.spanCount = Math.floor(currentPageWidth/80);
application.on("orientationChanged", function (e: application.OrientationChangedEventData) {
var currentPageWidth = platform.screen.mainScreen.heightDIPs
list.listViewLayout.spanCount = Math.floor(currentPageWidth / 80);
});

@@ -42,3 +40,3 @@ }

page.on(Page.loadedEvent, pageLoaded);
//<ActionBar title="{{ title }}">

@@ -60,4 +58,6 @@ let actionBar = new ActionBar();

let item = new ActionItem();
item.bind({ targetProperty: "text", sourceProperty: "imagePicker.selection.length", twoWay: false,
expression: "imagePicker.doneText + (imagePicker.mode === 'single' ? '' : ' (' + imagePicker.selection.length + ')')" });
item.bind({
targetProperty: "text", sourceProperty: "imagePicker.selection.length", twoWay: false,
expression: "imagePicker.doneText + (imagePicker.mode === 'single' ? '' : ' (' + imagePicker.selection.length + ')')"
});
item.ios.position = "right";

@@ -76,12 +76,9 @@ item.on(ActionItem.tapEvent, done);

let listViewGridLayout = new ListViewGridLayout();
listViewGridLayout.scrollDirection="Vertical";
listViewGridLayout.scrollDirection = "Vertical";
listViewGridLayout.spanCount = 4;
listViewGridLayout.itemHeight = 80;
listView.listViewLayout = listViewGridLayout;
listView.itemTemplate =
listView.itemTemplate =
"<GridLayout margin=\"1\" rows=\"auto\" tap=\"{{ toggleSelection }}\">" +
"<Image height=\"78\" width=\"78\" opacity=\"{{ selected ? 0.7 : 1 }}\" imageSource=\"{{ thumb }}\"/>" +
"<Border opacity=\"{{ selected ? 1 : 0 }}\" width=\"24\" height=\"24\" margin=\"2\" horizontalAlignment=\"right\"" +
"verticalAlignment=\"bottom\" borderWidth=\"1\" borderColor=\"white\" backgroundColor=\"blue\"" +
"borderRadius=\"12\"/>" +
"<Image height=\"78\" width=\"78\" opacity=\"{{ selected ? 0.7 : 1 }}\" src=\"{{ $value }}\"/>" +
"</GridLayout>";

@@ -92,2 +89,2 @@

return page;
}
}
import observable = require("data/observable");
import imagesource = require("image-source");
import imageAssetModule = require("image-asset");

@@ -17,4 +18,5 @@ export interface ImageOptions {

export class SelectedAsset extends observable.Observable {
export class SelectedAsset extends imageAssetModule.ImageAsset {
/**
* [Deprecated. SelectedAsset will be used directly as a source for the thumb image]
* A 100x100 pixels thumb of the selected image.

@@ -21,0 +23,0 @@ * This property will be initialized on demand. The first access will return undefined or null.

@@ -8,3 +8,3 @@ {

"name": "nativescript-imagepicker",
"version": "2.4.1",
"version": "2.5.0",
"nativescript": {

@@ -17,9 +17,9 @@ "platforms": {

"dependencies": {
"tns-core-modules": "*",
"tns-core-modules": ">=2.5.0",
"nativescript-telerik-ui": "*"
},
"main": "viewmodel.js",
"main": "viewmodel",
"devDependencies": {
"tns-platform-declarations": "next",
"typescript": "^2.0.3"
"typescript": "~2.0.10"
},

@@ -26,0 +26,0 @@ "scripts": {

@@ -13,3 +13,3 @@ # Image Picker for the NativeScript framework

- [Select and Upload](https://github.com/NativeScript/sample-ImageUpload)
- [imagepicker](https://github.com/NativeScript/nativescript-imagepicker/tree/release/examples/ExampleImgPick/app)
- [ImagePicker](https://github.com/NativeScript/nativescript-imagepicker/tree/master/examples/ExampleImgPick/app)

@@ -132,2 +132,2 @@ ## Installation

exports.onSelectSingleTap = onSelectSingleTap;
```
```
"use strict";
var observable = require("data/observable");
var imagesource = require("image-source");
var application = require("application");
var imageAssetModule = require("image-asset");
var Intent = android.content.Intent;

@@ -14,3 +14,3 @@ var Activity = android.app.Activity;

function SelectedAsset(uri) {
_super.call(this);
_super.call(this, SelectedAsset._calculateFileUri(uri));
this._uri = uri;

@@ -58,2 +58,13 @@ this._thumbRequested = false;

});
Object.defineProperty(SelectedAsset.prototype, "thumbAsset", {
get: function () {
return this._thumbAsset;
},
enumerable: true,
configurable: true
});
SelectedAsset.prototype.setThumbAsset = function (value) {
this._thumbAsset = value;
this.notifyPropertyChange("thumbAsset", value);
};
Object.defineProperty(SelectedAsset.prototype, "uri", {

@@ -69,3 +80,3 @@ get: function () {

if (!this._fileUri) {
this._fileUri = this._calculateFileUri();
this._fileUri = SelectedAsset._calculateFileUri(this._uri);
}

@@ -77,8 +88,7 @@ return this._fileUri;

});
SelectedAsset.prototype._calculateFileUri = function () {
var _this = this;
SelectedAsset._calculateFileUri = function (uri) {
var isKitKat = android.os.Build.VERSION.SDK_INT >= 19;
if (isKitKat && DocumentsContract.isDocumentUri(application.android.context, this._uri)) {
if (_this.isExternalStorageDocument(this._uri)) {
var docId = DocumentsContract.getDocumentId(this._uri);
if (isKitKat && DocumentsContract.isDocumentUri(application.android.context, uri)) {
if (SelectedAsset.isExternalStorageDocument(uri)) {
var docId = DocumentsContract.getDocumentId(uri);
var id = docId.split(":")[1];

@@ -90,9 +100,9 @@ var type = docId.split(":")[0];

}
else if (_this.isDownloadsDocument(this._uri)) {
var id = DocumentsContract.getDocumentId(this._uri);
else if (SelectedAsset.isDownloadsDocument(uri)) {
var id = DocumentsContract.getDocumentId(uri);
var contentUri = android.content.ContentUris.withAppendedId(android.net.Uri.parse("content://downloads/public_downloads"), long(id));
return _this.getDataColumn(contentUri, null, null);
return SelectedAsset.getDataColumn(contentUri, null, null);
}
else if (_this.isMediaDocument(this._uri)) {
var docId = DocumentsContract.getDocumentId(this._uri);
else if (SelectedAsset.isMediaDocument(uri)) {
var docId = DocumentsContract.getDocumentId(uri);
var split = docId.split(":");

@@ -113,11 +123,11 @@ var type = split[0];

var selectionArgs = [id];
return _this.getDataColumn(contentUri, selection, selectionArgs);
return SelectedAsset.getDataColumn(contentUri, selection, selectionArgs);
}
}
else {
if ("content" === this._uri.getScheme()) {
return _this.getDataColumn(this._uri, null, null);
if ("content" === uri.getScheme()) {
return SelectedAsset.getDataColumn(uri, null, null);
}
else if ("file" === this._uri.getScheme()) {
return this._uri.getPath();
else if ("file" === uri.getScheme()) {
return uri.getPath();
}

@@ -128,3 +138,3 @@ }

;
SelectedAsset.prototype.getDataColumn = function (uri, selection, selectionArgs) {
SelectedAsset.getDataColumn = function (uri, selection, selectionArgs) {
var cursor = null;

@@ -154,11 +164,11 @@ var columns = [MediaStore.MediaColumns.DATA];

;
SelectedAsset.prototype.isExternalStorageDocument = function (uri) {
SelectedAsset.isExternalStorageDocument = function (uri) {
return "com.android.externalstorage.documents" === uri.getAuthority();
};
;
SelectedAsset.prototype.isDownloadsDocument = function (uri) {
SelectedAsset.isDownloadsDocument = function (uri) {
return "com.android.providers.downloads.documents" === uri.getAuthority();
};
;
SelectedAsset.prototype.isMediaDocument = function (uri) {
SelectedAsset.isMediaDocument = function (uri) {
return "com.android.providers.media.documents" === uri.getAuthority();

@@ -175,2 +185,10 @@ };

};
SelectedAsset.prototype.decodeThumbAssetUri = function () {
var REQUIRED_SIZE = {
maxWidth: 100,
maxHeight: 100
};
this._thumbAsset = this.decodeUriForImageAsset(this._uri, REQUIRED_SIZE);
this.notifyPropertyChange("thumbAsset", this._thumbAsset);
};
SelectedAsset.prototype.getSampleSize = function (uri, options) {

@@ -205,6 +223,12 @@ var boundsOptions = new BitmapFactory.Options();

};
SelectedAsset.prototype.decodeUriForImageAsset = function (uri, options) {
var downsampleOptions = new BitmapFactory.Options();
downsampleOptions.inSampleSize = this.getSampleSize(uri, options);
var bitmap = BitmapFactory.decodeStream(this.openInputStream(uri), null, downsampleOptions);
return new imageAssetModule.ImageAsset(bitmap);
};
SelectedAsset.prototype.getByteBuffer = function (uri) {
var file = null;
try {
file = this.getContentResolver().openAssetFileDescriptor(uri, "r");
file = SelectedAsset.getContentResolver().openAssetFileDescriptor(uri, "r");
var length = file.getLength();

@@ -225,9 +249,9 @@ var buffer = java.nio.ByteBuffer.allocateDirect(length);

SelectedAsset.prototype.openInputStream = function (uri) {
return this.getContentResolver().openInputStream(uri);
return SelectedAsset.getContentResolver().openInputStream(uri);
};
SelectedAsset.prototype.getContentResolver = function () {
SelectedAsset.getContentResolver = function () {
return application.android.nativeApp.getContentResolver();
};
return SelectedAsset;
}(observable.Observable));
}(imageAssetModule.ImageAsset));
exports.SelectedAsset = SelectedAsset;

@@ -234,0 +258,0 @@ var ImagePicker = (function () {

@@ -5,2 +5,3 @@ import * as observable from "data/observable";

import * as platform from "platform";
import imageAssetModule = require("image-asset");

@@ -18,6 +19,7 @@ interface ArrayBufferStatic extends ArrayBufferConstructor {

export class SelectedAsset extends observable.Observable {
export class SelectedAsset extends imageAssetModule.ImageAsset {
private _uri: android.net.Uri;
private _thumb: imagesource.ImageSource;
private _thumbRequested: boolean;
private _thumbAsset: imageAssetModule.ImageAsset;
private _fileUri: string;

@@ -27,3 +29,3 @@ private _data: ArrayBuffer;

constructor(uri: android.net.Uri) {
super();
super(SelectedAsset._calculateFileUri(uri));
this._uri = uri;

@@ -61,2 +63,3 @@ this._thumbRequested = false;

//[Deprecated. Please use thumbAsset instead.]
get thumb(): imagesource.ImageSource {

@@ -69,2 +72,11 @@ if (!this._thumbRequested) {

get thumbAsset(): imageAssetModule.ImageAsset {
return this._thumbAsset;
}
protected setThumbAsset(value: imageAssetModule.ImageAsset): void {
this._thumbAsset = value;
this.notifyPropertyChange("thumbAsset", value);
}
get uri(): string {

@@ -76,3 +88,3 @@ return this._uri.toString();

if (!this._fileUri) {
this._fileUri = this._calculateFileUri();
this._fileUri = SelectedAsset._calculateFileUri(this._uri);
}

@@ -82,11 +94,9 @@ return this._fileUri;

private _calculateFileUri() {
var _this = this;
private static _calculateFileUri(uri : android.net.Uri) {
var isKitKat = android.os.Build.VERSION.SDK_INT >= 19;//android.os.Build.VERSION_CODES.KITKAT
if (isKitKat && DocumentsContract.isDocumentUri(application.android.context, this._uri)) {
if (isKitKat && DocumentsContract.isDocumentUri(application.android.context, uri)) {
// ExternalStorageProvider
if (_this.isExternalStorageDocument(this._uri)) {
var docId = DocumentsContract.getDocumentId(this._uri);
if (SelectedAsset.isExternalStorageDocument(uri)) {
var docId = DocumentsContract.getDocumentId(uri);
var id = docId.split(":")[1];

@@ -102,12 +112,12 @@ var type = docId.split(":")[0];

// DownloadsProvider
else if (_this.isDownloadsDocument(this._uri)) {
var id = DocumentsContract.getDocumentId(this._uri);
else if (SelectedAsset.isDownloadsDocument(uri)) {
var id = DocumentsContract.getDocumentId(uri);
var contentUri = android.content.ContentUris.withAppendedId(
android.net.Uri.parse("content://downloads/public_downloads"), long(id));
return _this.getDataColumn(contentUri, null, null);
return SelectedAsset.getDataColumn(contentUri, null, null);
}
// MediaProvider
else if (_this.isMediaDocument(this._uri)) {
var docId = DocumentsContract.getDocumentId(this._uri);
else if (SelectedAsset.isMediaDocument(uri)) {
var docId = DocumentsContract.getDocumentId(uri);
var split = docId.split(":");

@@ -129,3 +139,3 @@ var type = split[0];

return _this.getDataColumn(contentUri, selection, selectionArgs);
return SelectedAsset.getDataColumn(contentUri, selection, selectionArgs);
}

@@ -135,8 +145,8 @@ }

// MediaStore (and general)
if ("content" === this._uri.getScheme()) {
return _this.getDataColumn(this._uri, null, null);
if ("content" === uri.getScheme()) {
return SelectedAsset.getDataColumn(uri, null, null);
}
// FILE
else if ("file" === this._uri.getScheme()) {
return this._uri.getPath();
else if ("file" === uri.getScheme()) {
return uri.getPath();
}

@@ -148,3 +158,3 @@ }

private getDataColumn(uri: android.net.Uri, selection, selectionArgs) {
private static getDataColumn(uri: android.net.Uri, selection, selectionArgs) {

@@ -178,9 +188,9 @@ var cursor = null;

private isExternalStorageDocument(uri: android.net.Uri) {
private static isExternalStorageDocument(uri: android.net.Uri) {
return "com.android.externalstorage.documents" === uri.getAuthority();
};
private isDownloadsDocument(uri: android.net.Uri) {
private static isDownloadsDocument(uri: android.net.Uri) {
return "com.android.providers.downloads.documents" === uri.getAuthority();
};
private isMediaDocument(uri: android.net.Uri) {
private static isMediaDocument(uri: android.net.Uri) {
return "com.android.providers.media.documents" === uri.getAuthority();

@@ -197,6 +207,18 @@ };

// Decode with scale
this._thumb = this.decodeUri(this._uri, REQUIRED_SIZE);
this.notifyPropertyChange("thumb", this._thumb);
this._thumb = this.decodeUri(this._uri, REQUIRED_SIZE);
this.notifyPropertyChange("thumb", this._thumb);
}
private decodeThumbAssetUri(): void {
// Decode image size
var REQUIRED_SIZE = {
maxWidth: 100,
maxHeight: 100
};
// Decode with scale
this._thumbAsset = this.decodeUriForImageAsset(this._uri, REQUIRED_SIZE);
this.notifyPropertyChange("thumbAsset", this._thumbAsset);
}
/**

@@ -251,2 +273,14 @@ * Discovers the sample size that a BitmapFactory.Options object should have

/**
* Decodes the given URI using the given options.
* @param uri The URI that should be decoded into an ImageAsset.
* @param options The options that should be used to decode the image.
*/
private decodeUriForImageAsset(uri: android.net.Uri, options?: { maxWidth: number, maxHeight: number }): imageAssetModule.ImageAsset {
var downsampleOptions = new BitmapFactory.Options();
downsampleOptions.inSampleSize = this.getSampleSize(uri, options);
var bitmap = BitmapFactory.decodeStream(this.openInputStream(uri), null, downsampleOptions);
return new imageAssetModule.ImageAsset(bitmap);
}
/**
* Retrieves the raw data of the given file and exposes it as a byte buffer.

@@ -257,3 +291,3 @@ */

try {
file = this.getContentResolver().openAssetFileDescriptor(uri, "r");
file = SelectedAsset.getContentResolver().openAssetFileDescriptor(uri, "r");

@@ -278,6 +312,6 @@ // Determine how many bytes to allocate in memory based on the file length

private openInputStream(uri: android.net.Uri): java.io.InputStream {
return this.getContentResolver().openInputStream(uri);
return SelectedAsset.getContentResolver().openInputStream(uri);
}
private getContentResolver(): android.content.ContentResolver {
private static getContentResolver(): android.content.ContentResolver {
return application.android.nativeApp.getContentResolver();

@@ -376,2 +410,2 @@ }

return new ImagePicker(options);
}
}

@@ -5,2 +5,3 @@ "use strict";

var frame = require("ui/frame");
var imageAssetModule = require("image-asset");
var image_source = require("image-source");

@@ -14,2 +15,4 @@ if (global.TNS_WEBPACK) {

}
var IMAGE_WIDTH = 80;
var IMAGE_HEIGHT = 80;
function create(options) {

@@ -156,2 +159,13 @@ if (true) {

};
Object.defineProperty(Album.prototype, "thumbAsset", {
get: function () {
return this._thumbAsset;
},
enumerable: true,
configurable: true
});
Album.prototype.setThumbAsset = function (value) {
this._thumbAsset = value;
this.notifyPropertyChange("thumbAsset", value);
};
return Album;

@@ -193,8 +207,8 @@ }(data_observable.Observable));

return SelectedAsset;
}(data_observable.Observable));
}(imageAssetModule.ImageAsset));
exports.SelectedAsset = SelectedAsset;
var Asset = (function (_super) {
__extends(Asset, _super);
function Asset(album) {
_super.call(this);
function Asset(album, asset) {
_super.call(this, asset);
this._album = album;

@@ -276,2 +290,3 @@ this._image = null;

this._thumbRequestSize = CGSizeMake(80, 80);
this._options = options;
this._initialized = false;

@@ -322,2 +337,13 @@ }

};
ImagePickerPH.prototype.createPHImageThumbAsset = function (target, asset) {
PHImageManager.defaultManager().requestImageForAssetTargetSizeContentModeOptionsResultHandler(asset, this._thumbRequestSize, 1, this._thumbRequestOptions, function (target, uiImage, info) {
var imageAsset = new imageAssetModule.ImageAsset(uiImage);
imageAsset.options = {
width: this._options.maxWidth && this._options.maxWidth < IMAGE_WIDTH ? this._options.maxWidth : IMAGE_WIDTH,
height: this._options.maxHeight && this._options.IMAGE_HEIGHT < 80 ? this._options.IMAGE_HEIGHT : IMAGE_HEIGHT,
keepAspectRatio: true
};
target.setThumbAsset(imageAsset);
}.bind(this, target));
};
ImagePickerPH.prototype.createPHImage = function (image, options) {

@@ -364,5 +390,6 @@ return new Promise(function (resolve, reject) {

__extends(AlbumPH, _super);
function AlbumPH(imagePicker, title) {
function AlbumPH(imagePicker, title, options) {
_super.call(this, imagePicker, title);
this._setThumb = false;
this._options = options;
}

@@ -381,6 +408,8 @@ AlbumPH.prototype.addAssetsForFetchResult = function (result) {

AlbumPH.prototype.addAsset = function (asset) {
var item = new AssetPH(this, asset);
if (!this._setThumb) {
var imagePicker = this.imagePicker;
var item = new AssetPH(this, asset, this._options);
if (!this._setThumb && !imagePicker) {
this._setThumb = true;
this.imagePicker.createPHImageThumb(this, asset);
imagePicker.createPHImageThumb(this, asset);
imagePicker.createPHImageThumbAsset(this, asset);
}

@@ -398,5 +427,6 @@ if (this.imagePicker.newestFirst) {

__extends(AssetPH, _super);
function AssetPH(album, phAsset) {
_super.call(this, album);
function AssetPH(album, phAsset, options) {
_super.call(this, album, phAsset);
this._phAsset = phAsset;
this._initializeOptions(options);
}

@@ -421,2 +451,18 @@ Object.defineProperty(AssetPH.prototype, "ios", {

});
AssetPH.prototype._initializeOptions = function (options) {
if (options) {
this.options = {
width: options.maxWidth && options.maxWidth < IMAGE_WIDTH ? options.maxWidth : IMAGE_WIDTH,
height: options.maxHeight && options.maxHeight < IMAGE_HEIGHT ? options.maxHeight : IMAGE_HEIGHT,
keepAspectRatio: true
};
}
else {
this.options = {
width: IMAGE_WIDTH,
height: IMAGE_HEIGHT,
keepAspectRatio: true
};
}
};
AssetPH.prototype.getImage = function (options) {

@@ -423,0 +469,0 @@ return this.album.imagePicker.createPHImage(this._phAsset, options);

import data_observable = require("data/observable");
import data_observablearray = require("data/observable-array");
import frame = require("ui/frame");
import imageAssetModule = require("image-asset");

@@ -15,2 +16,5 @@ import image_source = require("image-source");

const IMAGE_WIDTH = 80;
const IMAGE_HEIGHT = 80;
interface ImageOptions {

@@ -117,2 +121,3 @@ maxWidth?: number;

private _thumb: image_source.ImageSource;
private _thumbAsset: imageAssetModule.ImageAsset;

@@ -138,2 +143,3 @@ constructor(imagePicker: ImagePicker, title: string) {

//[Deprecated. Please use thumbAsset instead.]
get thumb(): image_source.ImageSource {

@@ -147,5 +153,15 @@ return this._thumb;

}
get thumbAsset(): imageAssetModule.ImageAsset {
return this._thumbAsset;
}
protected setThumbAsset(value: imageAssetModule.ImageAsset): void {
this._thumbAsset = value;
this.notifyPropertyChange("thumbAsset", value);
}
}
export class SelectedAsset extends data_observable.Observable {
export class SelectedAsset extends imageAssetModule.ImageAsset {
// [Deprecated. SelectedAsset will be used directly as a source for the thumb image]
get thumb(): image_source.ImageSource {

@@ -173,3 +189,2 @@ return null;

export class Asset extends SelectedAsset {
private _selected: boolean;

@@ -182,4 +197,4 @@ private _album: Album;

constructor(album: Album) {
super();
constructor(album: Album, asset: PHAsset | UIImage) {
super(asset);
this._album = album;

@@ -193,2 +208,3 @@ this._image = null;

// [Deprecated. Asset will be used directly as a source for the thumb image]
get thumb(): image_source.ImageSource {

@@ -251,3 +267,2 @@ if (!this._thumbRequested) {

private _thumbRequestSize: CGSize;
private _initialized: boolean;

@@ -265,2 +280,3 @@

this._thumbRequestSize = CGSizeMake(80, 80);
this._options = options;

@@ -317,2 +333,15 @@ this._initialized = false;

createPHImageThumbAsset(target, asset: PHAsset): void {
PHImageManager.defaultManager().requestImageForAssetTargetSizeContentModeOptionsResultHandler(asset, this._thumbRequestSize, PHImageContentMode.AspectFill,
this._thumbRequestOptions, function (target, uiImage, info) {
var imageAsset = new imageAssetModule.ImageAsset(uiImage);
imageAsset.options = {
width: this._options.maxWidth && this._options.maxWidth < IMAGE_WIDTH ? this._options.maxWidth : IMAGE_WIDTH,
height: this._options.maxHeight && this._options.IMAGE_HEIGHT < 80 ? this._options.IMAGE_HEIGHT : IMAGE_HEIGHT,
keepAspectRatio: true
};
target.setThumbAsset(imageAsset);
}.bind(this, target));
}
/**

@@ -346,3 +375,3 @@ * Creates a new ImageSource from the given image, using the given sizing options.

imageSource.setNativeSource(createdImage);
// TODO: Determine whether runOnRunLoop is needed

@@ -384,6 +413,8 @@ // for callback or not. (See the data() implementation in AssetPH below)

private _setThumb: boolean;
private _options: ImageOptions;
constructor(imagePicker: ImagePicker, title: string) {
constructor(imagePicker: ImagePicker, title: string, options?: ImageOptions) {
super(imagePicker, title);
this._setThumb = false;
this._options = options;
}

@@ -403,6 +434,9 @@

addAsset(asset: PHAsset): void {
var item = new AssetPH(this, asset);
if (!this._setThumb) {
var imagePicker = <ImagePickerPH>this.imagePicker;
var item = new AssetPH(this, asset, this._options);
if (!this._setThumb && !imagePicker) {
this._setThumb = true;
(<ImagePickerPH>this.imagePicker).createPHImageThumb(this, asset);
imagePicker.createPHImageThumb(this, asset);
imagePicker.createPHImageThumbAsset(this, asset);
}

@@ -421,5 +455,6 @@ if (this.imagePicker.newestFirst) {

constructor(album: AlbumPH, phAsset: PHAsset) {
super(album);
constructor(album: AlbumPH, phAsset: PHAsset, options?: ImageOptions) {
super(album, phAsset);
this._phAsset = phAsset;
this._initializeOptions(options);
}

@@ -443,2 +478,18 @@

private _initializeOptions(options: ImageOptions): void {
if (options) {
this.options = {
width: options.maxWidth && options.maxWidth < IMAGE_WIDTH ? options.maxWidth : IMAGE_WIDTH,
height: options.maxHeight && options.maxHeight < IMAGE_HEIGHT ? options.maxHeight : IMAGE_HEIGHT,
keepAspectRatio: true
};
} else {
this.options = {
width: IMAGE_WIDTH,
height: IMAGE_HEIGHT,
keepAspectRatio: true
};
}
}
getImage(options?: ImageOptions): Promise<image_source.ImageSource> {

@@ -475,5 +526,5 @@ return (<ImagePickerPH>(<AlbumPH>this.album).imagePicker).createPHImage(this._phAsset, options);

if (data) {
resolve(data);
resolve(data);
} else {
reject(new Error("Failed to get image data."));
reject(new Error("Failed to get image data."));
}

@@ -480,0 +531,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc