Skip to content

Add Code to Close imagePicker #20

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 10 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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/ios/SOSPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import <Cordova/CDVPlugin.h>
#import "GMImagePickerController.h"


@interface SOSPicker : CDVPlugin < UINavigationControllerDelegate, UIScrollViewDelegate>
Expand All @@ -16,12 +17,14 @@
- (void) getPictures:(CDVInvokedUrlCommand *)command;
- (void) hasReadPermission:(CDVInvokedUrlCommand *)command;
- (void) requestReadPermission:(CDVInvokedUrlCommand *)command;
- (void) closeImagePicker:(CDVInvokedUrlCommand *)command;

- (UIImage*)imageByScalingNotCroppingForSize:(UIImage*)anImage toSize:(CGSize)frameSize;

@property (nonatomic, assign) NSInteger width;
@property (nonatomic, assign) NSInteger height;
@property (nonatomic, assign) NSInteger quality;
@property (nonatomic, assign) NSInteger outputType;
@property (nonatomic, assign) GMImagePickerController* imagePicker;

@end
10 changes: 10 additions & 0 deletions src/ios/SOSPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ - (void)launchGMImagePicker:(bool)allow_video title:(NSString *)title message:(N
picker.colsInPortrait = 4;
picker.colsInLandscape = 6;
picker.minimumInteritemSpacing = 2.0;
self.imagePicker = picker;

if(!disable_popover) {
picker.modalPresentationStyle = UIModalPresentationPopover;
Expand Down Expand Up @@ -280,5 +281,14 @@ -(void)assetsPickerControllerDidCancel:(GMImagePickerController *)picker
NSLog(@"GMImagePicker: User pressed cancel button");
}

- (void) closeImagePicker:(CDVInvokedUrlCommand *)command {
if (self.imagePicker.presentingViewController) {
CDVPluginResult* pluginResult = nil;
NSArray* emptyArray = [NSArray array];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:emptyArray];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.imagePicker.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
}

@end
4 changes: 4 additions & 0 deletions www/imagepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ ImagePicker.prototype.requestReadPermission = function(callback, failureCallback
return cordova.exec(callback, failureCallback, "ImagePicker", "requestReadPermission", []);
};

ImagePicker.prototype.closeImagePicker = function(callback) {
return cordova.exec(callback, null, "ImagePicker", "closeImagePicker", []);
};

/*
* success - success callback
* fail - error callback
Expand Down
Loading