Permalink
Browse files

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
  • Loading branch information...
Enrico Bern Hardy Tanuwidjaja authored and facebook-github-bot committed Nov 15, 2018
1 parent d9c2cda commit 4aeea4d2dc14cf02dc3766043e2938bf367c6170
Showing with 41 additions and 1 deletion.
  1. +41 −1 Libraries/CameraRoll/RCTImagePickerManager.m
@@ -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 @@ @implementation RCTImagePickerManager

@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 @@ - (dispatch_queue_t)methodQueue
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 @@ - (void)_dismissPicker:(UIImagePickerController *)picker args:(NSArray *)args
}
}

- (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

0 comments on commit 4aeea4d

Please sign in to comment.