Skip to content

Commit

Permalink
Fixed torchMode bug and refactored torch and flash mode code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
lwansbrough committed Jul 2, 2015
1 parent 2b2dd33 commit eba97d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
4 changes: 4 additions & 0 deletions Camera.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ var Camera = React.createClass({
if (typeof orientation === 'string') {
orientation = constants.Orientation[orientation];
}

if (typeof torchMode === 'string') {
torchMode = constants.TorchMode[torchMode];
}

if (typeof type === 'string') {
type = constants.Type[type];
Expand Down
34 changes: 19 additions & 15 deletions RCTCameraManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ - (id)init {
}];
}

RCT_EXPORT_METHOD(changeFlashMode:(NSInteger)flashMode) {
AVCaptureDevice *currentCaptureDevice = [self.captureDeviceInput device];
[self setFlashMode:flashMode forDevice:currentCaptureDevice];
}

RCT_EXPORT_METHOD(changeCamera:(NSInteger)camera) {
AVCaptureDevice *currentCaptureDevice = [self.captureDeviceInput device];
AVCaptureDevicePosition position = (AVCaptureDevicePosition)camera;
Expand Down Expand Up @@ -221,6 +216,19 @@ - (id)init {
self.previewLayer.videoGravity = aspect;
}

RCT_EXPORT_METHOD(changeFlashMode:(NSInteger)flashMode) {
AVCaptureDevice *device = [self.captureDeviceInput device];
NSError *error = nil;

if (![device hasFlash]) return;
if (![device lockForConfiguration:&error]) {
NSLog(@"%@", error);
return;
}
[self setFlashMode:flashMode forDevice:device];
[device unlockForConfiguration];
}

RCT_EXPORT_METHOD(changeOrientation:(NSInteger)orientation) {
self.previewLayer.connection.videoOrientation = orientation;
}
Expand All @@ -229,17 +237,13 @@ - (id)init {
AVCaptureDevice *device = [self.captureDeviceInput device];
NSError *error = nil;

if ([device hasTorch]) {
if ([device lockForConfiguration:&error])
{
[device setTorchMode: torchMode];
[device unlockForConfiguration];
}
else
{
NSLog(@"%@", error);
}
if (![device hasTorch]) return;
if (![device lockForConfiguration:&error]) {
NSLog(@"%@", error);
return;
}
[device setTorchMode: torchMode];
[device unlockForConfiguration];
}

RCT_EXPORT_METHOD(capture:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback) {
Expand Down

0 comments on commit eba97d2

Please sign in to comment.