Skip to content
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

feat(ios): Implement 'animated' property (CB-11629) #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ capturing a video clip, the `CaptureErrorCB` callback executes with a

### Properties

- __animated__: Whether or not the audio recording interface shows and hides using an animatied transition. (defaults to true).

- __limit__: The maximum number of audio clips the device user can record in a single capture operation. The value must be greater than or equal to 1 (defaults to 1).

- __duration__: The maximum duration of an audio sound clip, in seconds.
Expand All @@ -312,28 +314,35 @@ capturing a video clip, the `CaptureErrorCB` callback executes with a

### Amazon Fire OS Quirks

- The __animated__ property is not supported.
- The `duration` parameter is not supported. Recording lengths cannot be limited programmatically.

### Android Quirks

- The __animated__ property is not supported.
- The `duration` parameter is not supported. Recording lengths can't be limited programmatically.

### BlackBerry 10 Quirks

- The __animated__ property is not supported.
- The `duration` parameter is not supported. Recording lengths can't be limited programmatically.
- The `limit` parameter is not supported, so only one recording can be created for each invocation.

### iOS Quirks

- The `limit` parameter is not supported, so only one recording can be created for each invocation.

### Windows Quirks
- The __animated__ property is not supported.

## CaptureImageOptions

> Encapsulates image capture configuration options.

### Properties

- __animated__: Whether or not the camera interface shows and hides using an animatied transition. (defaults to true).

- __limit__: The maximum number of images the user can capture in a single capture operation. The value must be greater than or equal to 1 (defaults to 1).

### Example
Expand All @@ -343,17 +352,34 @@ capturing a video clip, the `CaptureErrorCB` callback executes with a

navigator.device.capture.captureImage(captureSuccess, captureError, options);

### Amazon Fire OS Quirks

- The __animated__ property is not supported.

### Android Quirks

- The __animated__ property is not supported.

### BlackBerry 10 Quirks

- The __animated__ property is not supported.

### iOS Quirks

- The __limit__ parameter is not supported, and only one image is taken per invocation.

### Windows Quirks

- The __animated__ property is not supported.

## CaptureVideoOptions

> Encapsulates video capture configuration options.

### Properties

- __animated__: Whether or not the camera interface shows and hides using an animatied transition. (defaults to true).

- __limit__: The maximum number of video clips the device's user can capture in a single capture operation. The value must be greater than or equal to 1 (defaults to 1).

- __duration__: The maximum duration of a video clip, in seconds.
Expand All @@ -365,16 +391,26 @@ capturing a video clip, the `CaptureErrorCB` callback executes with a

navigator.device.capture.captureVideo(captureSuccess, captureError, options);

### Amazon Fire OS Quirks

- The __animated__ property is not supported.

### BlackBerry 10 Quirks

- The __animated__ property is not supported.
- The __duration__ property is ignored, so the length of recordings can't be limited programmatically.

### iOS Quirks

- The __limit__ property is ignored. Only one video is recorded per invocation.

### Windows Quirks

- The __animated__ property is not supported.

### Android Quirks

- The __animated__ property is not supported.
- Android supports an additional __quality__ property, to allow capturing video at different qualities. A value of `1` ( the default ) means high quality and value of `0` means low quality, suitable for MMS messages.
See [here](http://developer.android.com/reference/android/provider/MediaStore.html#EXTRA_VIDEO_QUALITY) for more details.

Expand Down
4 changes: 4 additions & 0 deletions src/ios/CDVCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ typedef NSUInteger CDVCaptureError;
{
CDVImagePicker* pickerController;
BOOL inUse;
BOOL isAnimated;
}
@property BOOL inUse;
@property BOOL isAnimated;
- (void)captureAudio:(CDVInvokedUrlCommand*)command;
- (void)captureImage:(CDVInvokedUrlCommand*)command;
- (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCallbackId:(NSString*)callbackId;
Expand Down Expand Up @@ -92,6 +94,7 @@ typedef NSUInteger CDVCaptureError;
CDVPluginResult* pluginResult;
NSTimer* timer;
BOOL isTimed;
BOOL isAnimated;
}
@property (nonatomic) CDVCaptureError errorCode;
@property (nonatomic, copy) NSString* callbackId;
Expand All @@ -108,6 +111,7 @@ typedef NSUInteger CDVCaptureError;
@property (nonatomic, strong) CDVPluginResult* pluginResult;
@property (nonatomic, strong) NSTimer* timer;
@property (nonatomic) BOOL isTimed;
@property (nonatomic) BOOL isAnimated;

- (id)initWithCommand:(CDVPlugin*)theCommand duration:(NSNumber*)theDuration callbackId:(NSString*)theCallbackId;
- (void)processButton:(id)sender;
Expand Down
31 changes: 24 additions & 7 deletions src/ios/CDVCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ - (void)viewWillAppear:(BOOL)animated {

@implementation CDVCapture
@synthesize inUse;
@synthesize isAnimated;

- (void)pluginInitialize
{
self.inUse = NO;
self.isAnimated = YES;
}

- (void)captureAudio:(CDVInvokedUrlCommand*)command
Expand All @@ -91,6 +93,11 @@ - (void)captureAudio:(CDVInvokedUrlCommand*)command
options = [NSDictionary dictionary];
}

NSNumber* animated = [options objectForKey:@"animated"];
if (animated) {
self.isAnimated = [animated boolValue];
}

NSNumber* duration = [options objectForKey:@"duration"];
// the default value of duration is 0 so use nil (no duration) if default value
if (duration) {
Expand All @@ -105,13 +112,14 @@ - (void)captureAudio:(CDVInvokedUrlCommand*)command
} else {
// all the work occurs here
CDVAudioRecorderViewController* audioViewController = [[CDVAudioRecorderViewController alloc] initWithCommand:self duration:duration callbackId:callbackId];
audioViewController.isAnimated = self.isAnimated;

// Now create a nav controller and display the view...
CDVAudioNavigationController* navController = [[CDVAudioNavigationController alloc] initWithRootViewController:audioViewController];

self.inUse = YES;

[self.viewController presentViewController:navController animated:YES completion:nil];
[self.viewController presentViewController:navController animated:self.isAnimated completion:nil];
}

if (result) {
Expand All @@ -131,6 +139,10 @@ - (void)captureImage:(CDVInvokedUrlCommand*)command
// options could contain limit and mode neither of which are supported at this time
// taking more than one picture (limit) is only supported if provide own controls via cameraOverlayView property
// can support mode in OS
NSNumber* animated = [options objectForKey:@"animated"];
if (animated) {
self.isAnimated = [animated boolValue];
}

if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
NSLog(@"Capture.imageCapture: camera not available.");
Expand Down Expand Up @@ -158,7 +170,7 @@ - (void)captureImage:(CDVInvokedUrlCommand*)command
// CDVImagePicker specific property
pickerController.callbackId = callbackId;

[self.viewController presentViewController:pickerController animated:YES completion:nil];
[self.viewController presentViewController:pickerController animated:self.isAnimated completion:nil];
}
}

Expand Down Expand Up @@ -221,6 +233,11 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command

// options could contain limit, duration and mode
// taking more than one video (limit) is only supported if provide own controls via cameraOverlayView property
NSNumber* animated = [options objectForKey:@"animated"];
if (animated) {
self.isAnimated = [animated boolValue];
}

NSNumber* duration = [options objectForKey:@"duration"];
NSString* mediaType = nil;

Expand Down Expand Up @@ -270,7 +287,7 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command
// CDVImagePicker specific property
pickerController.callbackId = callbackId;

[self.viewController presentViewController:pickerController animated:YES completion:nil];
[self.viewController presentViewController:pickerController animated:self.isAnimated completion:nil];
}
}

Expand Down Expand Up @@ -496,7 +513,7 @@ - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingM
CDVImagePicker* cameraPicker = (CDVImagePicker*)picker;
NSString* callbackId = cameraPicker.callbackId;

[[picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];
[[picker presentingViewController] dismissViewControllerAnimated:self.isAnimated completion:nil];

CDVPluginResult* result = nil;

Expand Down Expand Up @@ -533,7 +550,7 @@ - (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
CDVImagePicker* cameraPicker = (CDVImagePicker*)picker;
NSString* callbackId = cameraPicker.callbackId;

[[picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];
[[picker presentingViewController] dismissViewControllerAnimated:self.isAnimated completion:nil];

CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_NO_MEDIA_FILES];
[self.commandDelegate sendPluginResult:result callbackId:callbackId];
Expand Down Expand Up @@ -566,7 +583,7 @@ @interface CDVAudioRecorderViewController () {
@end

@implementation CDVAudioRecorderViewController
@synthesize errorCode, callbackId, duration, captureCommand, doneButton, recordingView, recordButton, recordImage, stopRecordImage, timerLabel, avRecorder, avSession, pluginResult, timer, isTimed;
@synthesize errorCode, callbackId, duration, captureCommand, doneButton, recordingView, recordButton, recordImage, stopRecordImage, timerLabel, avRecorder, avSession, pluginResult, timer, isTimed, isAnimated;

- (NSString*)resolveImageResource:(NSString*)resource
{
Expand Down Expand Up @@ -850,7 +867,7 @@ - (void)stopRecordingCleanup
- (void)dismissAudioView:(id)sender
{
// called when done button pressed or when error condition to do cleanup and remove view
[[self.captureCommand.viewController.presentedViewController presentingViewController] dismissViewControllerAnimated:YES completion:nil];
[[self.captureCommand.viewController.presentedViewController presentingViewController] dismissViewControllerAnimated:self.isAnimated completion:nil];

if (!self.pluginResult) {
// return error
Expand Down