Changed front-facing camera so that it shows consistent image during capture and preview

Summary: Changed front-facing camera so that it shows consistent image during capture and preview

Reviewed By: mmmulani

Differential Revision: D13012715

fbshipit-source-id: 043cd9178fc49ef9e8e628a866dd8e52434f7306
This commit is contained in:
Enrico Bern Hardy Tanuwidjaja 2018-11-15 12:08:44 -08:00 коммит произвёл Facebook Github Bot
Родитель d9c2cdae41
Коммит 4aeea4d2dc
1 изменённых файлов: 41 добавлений и 1 удалений

Просмотреть файл

@ -16,6 +16,16 @@
#import <React/RCTRootView.h>
#import <React/RCTUtils.h>
@interface RCTImagePickerController : UIImagePickerController
@property (nonatomic, assign) BOOL unmirrorFrontFacingCamera;
@end
@implementation RCTImagePickerController
@end
@interface RCTImagePickerManager () <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@end
@ -31,6 +41,22 @@ RCT_EXPORT_MODULE(ImagePickerIOS);
@synthesize bridge = _bridge;
- (id)init
{
if (self = [super init]) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(cameraChanged:)
name:@"AVCaptureDeviceDidStartRunningNotification"
object:nil];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"AVCaptureDeviceDidStartRunningNotification" object:nil];
}
- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
@ -56,9 +82,10 @@ RCT_EXPORT_METHOD(openCameraDialog:(NSDictionary *)config
return;
}
UIImagePickerController *imagePicker = [UIImagePickerController new];
RCTImagePickerController *imagePicker = [RCTImagePickerController new];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.unmirrorFrontFacingCamera = [RCTConvert BOOL:config[@"unmirrorFrontFacingCamera"]];
if ([RCTConvert BOOL:config[@"videoMode"]]) {
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
@ -175,4 +202,17 @@ didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info
}
}
- (void)cameraChanged:(NSNotification *)notification
{
for (UIImagePickerController *picker in _pickers) {
if ([picker isKindOfClass:[RCTImagePickerController class]]
&& ((RCTImagePickerController *)picker).unmirrorFrontFacingCamera
&& picker.cameraDevice == UIImagePickerControllerCameraDeviceFront) {
picker.cameraViewTransform = CGAffineTransformScale(CGAffineTransformIdentity, -1, 1);
} else {
picker.cameraViewTransform = CGAffineTransformIdentity;
}
}
}
@end