16
16
#import < React/RCTRootView.h>
17
17
#import < React/RCTUtils.h>
18
18
19
+ @interface RCTImagePickerController : UIImagePickerController
20
+
21
+ @property (nonatomic , assign ) BOOL unmirrorFrontFacingCamera;
22
+
23
+ @end
24
+
25
+ @implementation RCTImagePickerController
26
+
27
+ @end
28
+
19
29
@interface RCTImagePickerManager () <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
20
30
21
31
@end
@@ -31,6 +41,22 @@ @implementation RCTImagePickerManager
31
41
32
42
@synthesize bridge = _bridge;
33
43
44
+ - (id )init
45
+ {
46
+ if (self = [super init ]) {
47
+ [[NSNotificationCenter defaultCenter ] addObserver: self
48
+ selector: @selector (cameraChanged: )
49
+ name: @" AVCaptureDeviceDidStartRunningNotification"
50
+ object: nil ];
51
+ }
52
+ return self;
53
+ }
54
+
55
+ - (void )dealloc
56
+ {
57
+ [[NSNotificationCenter defaultCenter ] removeObserver: self name: @" AVCaptureDeviceDidStartRunningNotification" object: nil ];
58
+ }
59
+
34
60
- (dispatch_queue_t )methodQueue
35
61
{
36
62
return dispatch_get_main_queue ();
@@ -56,9 +82,10 @@ - (dispatch_queue_t)methodQueue
56
82
return ;
57
83
}
58
84
59
- UIImagePickerController *imagePicker = [UIImagePickerController new ];
85
+ RCTImagePickerController *imagePicker = [RCTImagePickerController new ];
60
86
imagePicker.delegate = self;
61
87
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
88
+ imagePicker.unmirrorFrontFacingCamera = [RCTConvert BOOL: config[@" unmirrorFrontFacingCamera" ]];
62
89
63
90
if ([RCTConvert BOOL: config[@" videoMode" ]]) {
64
91
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
@@ -175,4 +202,17 @@ - (void)_dismissPicker:(UIImagePickerController *)picker args:(NSArray *)args
175
202
}
176
203
}
177
204
205
+ - (void )cameraChanged : (NSNotification *)notification
206
+ {
207
+ for (UIImagePickerController *picker in _pickers) {
208
+ if ([picker isKindOfClass: [RCTImagePickerController class ]]
209
+ && ((RCTImagePickerController *)picker).unmirrorFrontFacingCamera
210
+ && picker.cameraDevice == UIImagePickerControllerCameraDeviceFront) {
211
+ picker.cameraViewTransform = CGAffineTransformScale (CGAffineTransformIdentity , -1 , 1 );
212
+ } else {
213
+ picker.cameraViewTransform = CGAffineTransformIdentity ;
214
+ }
215
+ }
216
+ }
217
+
178
218
@end
0 commit comments