Skip to content

Commit

Permalink
Changed front-facing camera so that it shows consistent image during …
Browse files Browse the repository at this point in the history
…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 16, 2018
1 parent d9c2cda commit 4aeea4d
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion Libraries/CameraRoll/RCTImagePickerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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.