2015-04-02 02:40:03 -07:00
|
|
|
#import "RCTBridge.h"
|
2015-03-31 18:02:57 -07:00
|
|
|
#import "RCTCamera.h"
|
2015-04-02 02:40:03 -07:00
|
|
|
#import "RCTCameraManager.h"
|
2015-03-31 18:02:57 -07:00
|
|
|
#import "RCTLog.h"
|
2015-04-08 13:51:31 -07:00
|
|
|
#import "RCTUtils.h"
|
2015-04-10 19:56:30 -07:00
|
|
|
|
2015-03-31 18:02:57 -07:00
|
|
|
#import <AVFoundation/AVFoundation.h>
|
|
|
|
|
|
|
|
@implementation RCTCamera
|
|
|
|
|
2015-05-03 18:32:32 -07:00
|
|
|
- (void)setAspect:(NSInteger)aspect
|
2015-03-31 18:02:57 -07:00
|
|
|
{
|
2015-07-09 20:11:50 -07:00
|
|
|
NSString *aspectString;
|
|
|
|
switch (aspect) {
|
|
|
|
default:
|
|
|
|
case RCTCameraAspectFill:
|
|
|
|
aspectString = AVLayerVideoGravityResizeAspectFill;
|
|
|
|
break;
|
|
|
|
case RCTCameraAspectFit:
|
|
|
|
aspectString = AVLayerVideoGravityResizeAspect;
|
|
|
|
break;
|
|
|
|
case RCTCameraAspectStretch:
|
|
|
|
aspectString = AVLayerVideoGravityResize;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
[self.manager changeAspect:aspectString];
|
2015-03-31 19:27:18 -07:00
|
|
|
}
|
|
|
|
|
2015-05-01 14:33:23 -07:00
|
|
|
- (void)setType:(NSInteger)type
|
2015-03-31 19:27:18 -07:00
|
|
|
{
|
2015-07-09 20:11:50 -07:00
|
|
|
if (self.manager.session.isRunning) {
|
|
|
|
[self.manager changeCamera:type];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.manager.presetCamera = type;
|
|
|
|
}
|
|
|
|
[self.manager initializeCaptureSessionInput:AVMediaTypeVideo];
|
2015-04-01 10:32:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setOrientation:(NSInteger)orientation
|
|
|
|
{
|
2015-07-09 20:11:50 -07:00
|
|
|
if (orientation == RCTCameraOrientationAuto) {
|
|
|
|
[self.manager changeOrientation:[UIApplication sharedApplication].statusBarOrientation];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
|
|
|
|
[self.manager changeOrientation:orientation];
|
|
|
|
}
|
2015-03-31 18:02:57 -07:00
|
|
|
}
|
|
|
|
|
2015-05-31 00:36:55 +08:00
|
|
|
- (void)setFlashMode:(NSInteger)flashMode
|
|
|
|
{
|
2015-07-09 20:11:50 -07:00
|
|
|
[self.manager changeFlashMode:flashMode];
|
2015-05-31 00:36:55 +08:00
|
|
|
}
|
|
|
|
|
2015-06-15 20:58:36 +02:00
|
|
|
- (void)setTorchMode:(NSInteger)torchMode
|
|
|
|
{
|
2015-07-09 20:11:50 -07:00
|
|
|
[self.manager changeTorchMode:torchMode];
|
2015-06-15 20:58:36 +02:00
|
|
|
}
|
|
|
|
|
2015-04-10 19:56:30 -07:00
|
|
|
- (id)initWithManager:(RCTCameraManager*)manager
|
2015-03-31 18:02:57 -07:00
|
|
|
{
|
2015-07-09 20:11:50 -07:00
|
|
|
|
|
|
|
if ((self = [super init])) {
|
|
|
|
self.manager = manager;
|
|
|
|
[self.manager initializeCaptureSessionInput:AVMediaTypeVideo];
|
2015-07-19 13:02:35 -07:00
|
|
|
[self.manager startSession];
|
2015-07-09 20:11:50 -07:00
|
|
|
}
|
|
|
|
return self;
|
2015-03-31 18:02:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)layoutSubviews
|
|
|
|
{
|
2015-07-09 20:11:50 -07:00
|
|
|
[super layoutSubviews];
|
|
|
|
self.manager.previewLayer.frame = self.bounds;
|
|
|
|
[self setBackgroundColor:[UIColor blackColor]];
|
|
|
|
[self.layer insertSublayer:self.manager.previewLayer atIndex:0];
|
2015-03-31 18:02:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex
|
|
|
|
{
|
2015-07-09 20:11:50 -07:00
|
|
|
[self insertSubview:view atIndex:atIndex + 1];
|
|
|
|
return;
|
2015-03-31 18:02:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)removeReactSubview:(UIView *)subview
|
|
|
|
{
|
2015-07-09 20:11:50 -07:00
|
|
|
[subview removeFromSuperview];
|
|
|
|
return;
|
2015-03-31 18:02:57 -07:00
|
|
|
}
|
|
|
|
|
2015-06-02 14:34:03 -07:00
|
|
|
- (void)removeFromSuperview
|
|
|
|
{
|
2015-07-19 16:24:55 -07:00
|
|
|
[self.manager stopSession];
|
2015-06-04 14:37:36 -07:00
|
|
|
[super removeFromSuperview];
|
2015-06-02 14:34:03 -07:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
|
|
|
|
}
|
|
|
|
|
2015-05-01 14:33:23 -07:00
|
|
|
- (void)orientationChanged:(NSNotification *)notification{
|
2015-07-09 20:11:50 -07:00
|
|
|
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
|
|
|
|
[self.manager changeOrientation:orientation];
|
2015-05-01 14:33:23 -07:00
|
|
|
}
|
|
|
|
|
2015-03-31 18:02:57 -07:00
|
|
|
@end
|