Skip to content

Handle user pressing cancel button for ios/ add Error for Android #66

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 2 commits into from
Nov 3, 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
3 changes: 3 additions & 0 deletions src/camera.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export let takePicture = function (options?): Promise<any> {
keepAspectRatio: shouldKeepAspectRatio
};
resolve(asset);
} else if (resultCode === android.app.Activity.RESULT_CANCELED) {
// User cancelled the image capture
reject(new Error("cancelled"));
}
});

Expand Down
14 changes: 9 additions & 5 deletions src/camera.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic
}

private _callback: (result?) => void;
private _errorCallback: (result?) => void;

private _width: number;
private _height: number;
private _keepAspectRatio: boolean;
private _saveToGallery: boolean;

public initWithCallback(callback: (result?) => void): UIImagePickerControllerDelegateImpl {
public initWithCallback(callback: (result?) => void, errorCallback: (result?) => void): UIImagePickerControllerDelegateImpl {
this._callback = callback;
this._errorCallback = errorCallback;
return this;
}

public initWithCallbackAndOptions(callback: (result?) => void, options?): UIImagePickerControllerDelegateImpl {
public initWithCallbackAndOptions(callback: (result?) => void, errorCallback: (result?) => void, options?): UIImagePickerControllerDelegateImpl {
this._callback = callback;
this._errorCallback = errorCallback;
if (options) {
this._width = options.width;
this._height = options.height;
Expand Down Expand Up @@ -117,6 +120,7 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic
imagePickerControllerDidCancel(picker): void {
picker.presentingViewController.dismissViewControllerAnimatedCompletion(true, null);
listener = null;
this._errorCallback(new Error("cancelled"));
}
}

Expand Down Expand Up @@ -144,13 +148,13 @@ export let takePicture = function (options): Promise<any> {

if (reqWidth && reqHeight) {
listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions(
resolve, { width: reqWidth, height: reqHeight, keepAspectRatio: keepAspectRatio, saveToGallery: saveToGallery });
resolve, reject, { width: reqWidth, height: reqHeight, keepAspectRatio: keepAspectRatio, saveToGallery: saveToGallery });
} else if (saveToGallery) {
listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions(
resolve, { saveToGallery: saveToGallery, keepAspectRatio: keepAspectRatio });
resolve, reject, { saveToGallery: saveToGallery, keepAspectRatio: keepAspectRatio });
}
else {
listener = UIImagePickerControllerDelegateImpl.new().initWithCallback(resolve);
listener = UIImagePickerControllerDelegateImpl.new().initWithCallback(resolve, reject);
}
imagePickerController.delegate = listener;

Expand Down