Skip to content

Commit

Permalink
Implement stop() to close CAMERA or PHOTOLIBRARY
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitya Santosh committed Dec 6, 2023
1 parent 9eecbaa commit 41b7803
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/android/CameraLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ else if ((this.srcType == PHOTOLIBRARY) || (this.srcType == SAVEDPHOTOALBUM)) {
r.setKeepCallback(true);
callbackContext.sendPluginResult(r);

return true;
} if (action.equals("stop")) {
this.stopCamera();
return true;
}
return false;
Expand Down Expand Up @@ -352,6 +355,16 @@ public void takePicture(int returnType, int encodingType)
// LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
}

public void stopCamera() {
LOG.d(LOG_TAG,"Stopping Camera");
try {
this.cordova.getActivity().finishActivity((CAMERA + 1) * 16 + returnType + 1);
this.cordova.getActivity().finishActivity((PHOTOLIBRARY + 1) * 16 + returnType + 1);
} catch(Exception e) {
LOG.e(LOG_TAG, "Error in closing Camera/Picker");
}
}

/**
* Create a file in the applications temporary directory based upon the supplied encoding.
*
Expand Down
1 change: 1 addition & 0 deletions src/ios/CDVCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ typedef NSUInteger CDVMediaType;
*/
- (void)takePicture:(CDVInvokedUrlCommand*)command;
- (void)cleanup:(CDVInvokedUrlCommand*)command;
- (void)stop:(CDVInvokedUrlCommand*)command;
- (void)repositionPopover:(CDVInvokedUrlCommand*)command;

- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info;
Expand Down
10 changes: 10 additions & 0 deletions src/ios/CDVCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ - (void)takePicture:(CDVInvokedUrlCommand*)command
}];
}

- (void)stop:(CDVInvokedUrlCommand*)command {
if (self.pickerController) {
NSLog(@"Closing Camera/Photo Library");
[self.pickerController dismissViewControllerAnimated:YES completion:^{
self.hasPendingOperation = NO;
self.pickerController = nil;
}];
}
}

- (void)showCameraPicker:(NSString*)callbackId withOptions:(CDVPictureOptions *) pictureOptions
{
// Perform UI operations on the main thread
Expand Down
7 changes: 7 additions & 0 deletions www/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ cameraExport.getPicture = function (successCallback, errorCallback, options) {
// return new CameraPopoverHandle();
};

/**
* Closes the Camera on calling this method
*/
cameraExport.stop = function (successCallback, errorCallback) {
exec(successCallback, errorCallback, 'Camera', 'stop', []);

Check failure on line 158 in www/Camera.js

View workflow job for this annotation

GitHub Actions / Lint Test

Unexpected tab character

Check failure on line 158 in www/Camera.js

View workflow job for this annotation

GitHub Actions / Lint Test

Expected indentation of 4 spaces but found 1 tab
};

/**
* Removes intermediate image files that are kept in temporary storage
* after calling [`camera.getPicture`]{@link module:camera.getPicture}. Applies only when the value of
Expand Down

0 comments on commit 41b7803

Please sign in to comment.