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:
Родитель
d9c2cdae41
Коммит
4aeea4d2dc
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче