mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #2078 from victorsosa/master
Added save to gallery option - IOS
This commit is contained in:
@@ -15,6 +15,7 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic
|
||||
private _width: number;
|
||||
private _height: number;
|
||||
private _keepAspectRatio: boolean;
|
||||
private _saveToGallery: boolean;
|
||||
|
||||
public initWithCallback(callback: (result?) => void): UIImagePickerControllerDelegateImpl {
|
||||
this._callback = callback;
|
||||
@@ -26,7 +27,7 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic
|
||||
if (options) {
|
||||
this._width = options.width;
|
||||
this._height = options.height;
|
||||
|
||||
this._saveToGallery = options.saveToGallery;
|
||||
this._keepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
|
||||
}
|
||||
return this;
|
||||
@@ -57,9 +58,12 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic
|
||||
var imageSource: typeof imageSourceModule = require("image-source");
|
||||
|
||||
var imageSourceResult = image ? imageSource.fromNativeSource(image) : imageSource.fromNativeSource(source);
|
||||
|
||||
|
||||
if (this._callback) {
|
||||
this._callback(imageSourceResult);
|
||||
if(this._saveToGallery) {
|
||||
UIImageWriteToSavedPhotosAlbum(imageSourceResult.ios, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,14 +86,18 @@ export var takePicture = function (options): Promise<any> {
|
||||
var reqWidth = 0;
|
||||
var reqHeight = 0;
|
||||
var keepAspectRatio = true;
|
||||
var saveToGallery = true;
|
||||
if (options) {
|
||||
reqWidth = options.width || 0;
|
||||
reqHeight = options.height || reqWidth;
|
||||
keepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
|
||||
saveToGallery = options.saveToGallery ? true : false;
|
||||
}
|
||||
if (reqWidth && reqHeight) {
|
||||
listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions(resolve, { width: reqWidth, height: reqHeight, keepAspectRatio: keepAspectRatio });
|
||||
}
|
||||
listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions(resolve, { width: reqWidth, height: reqHeight, keepAspectRatio: keepAspectRatio, saveToGallery: saveToGallery });
|
||||
} else if (saveToGallery) {
|
||||
listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions(resolve, { saveToGallery: saveToGallery });
|
||||
}
|
||||
else {
|
||||
listener = UIImagePickerControllerDelegateImpl.new().initWithCallback(resolve);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user