forked from react-native-camera/react-native-camera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRCTCamera.m
101 lines (86 loc) · 2.53 KB
/
RCTCamera.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#import "RCTBridge.h"
#import "RCTCamera.h"
#import "RCTCameraManager.h"
#import "RCTLog.h"
#import "RCTUtils.h"
#import <AVFoundation/AVFoundation.h>
@implementation RCTCamera
- (void)setAspect:(NSInteger)aspect
{
NSString *aspectString;
switch (aspect) {
default:
case RCTCameraAspectFill:
aspectString = AVLayerVideoGravityResizeAspectFill;
break;
case RCTCameraAspectFit:
aspectString = AVLayerVideoGravityResizeAspect;
break;
case RCTCameraAspectStretch:
aspectString = AVLayerVideoGravityResize;
break;
}
[self.manager changeAspect:aspectString];
}
- (void)setType:(NSInteger)type
{
if (self.manager.session.isRunning) {
[self.manager changeCamera:type];
}
else {
self.manager.presetCamera = type;
}
}
- (void)setOrientation:(NSInteger)orientation
{
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];
}
}
- (void)setFlashMode:(NSInteger)flashMode
{
[self.manager changeFlashMode:flashMode];
}
- (void)setTorchMode:(NSInteger)torchMode
{
[self.manager changeTorchMode:torchMode];
}
- (id)initWithManager:(RCTCameraManager*)manager
{
if ((self = [super init])) {
self.manager = manager;
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
self.manager.previewLayer.frame = self.bounds;
[self setBackgroundColor:[UIColor blackColor]];
[self.layer insertSublayer:self.manager.previewLayer atIndex:0];
}
- (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex
{
[self insertSubview:view atIndex:atIndex + 1];
return;
}
- (void)removeReactSubview:(UIView *)subview
{
[subview removeFromSuperview];
return;
}
- (void)removeFromSuperview
{
[super removeFromSuperview];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged:(NSNotification *)notification{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
[self.manager changeOrientation:orientation];
}
@end