mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-28 20:25:33 +08:00
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:
committed by
Facebook Github Bot
parent
d9c2cdae41
commit
4aeea4d2dc
@@ -16,6 +16,16 @@
|
|||||||
#import <React/RCTRootView.h>
|
#import <React/RCTRootView.h>
|
||||||
#import <React/RCTUtils.h>
|
#import <React/RCTUtils.h>
|
||||||
|
|
||||||
|
@interface RCTImagePickerController : UIImagePickerController
|
||||||
|
|
||||||
|
@property (nonatomic, assign) BOOL unmirrorFrontFacingCamera;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation RCTImagePickerController
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@interface RCTImagePickerManager () <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
|
@interface RCTImagePickerManager () <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -31,6 +41,22 @@ RCT_EXPORT_MODULE(ImagePickerIOS);
|
|||||||
|
|
||||||
@synthesize bridge = _bridge;
|
@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
|
- (dispatch_queue_t)methodQueue
|
||||||
{
|
{
|
||||||
return dispatch_get_main_queue();
|
return dispatch_get_main_queue();
|
||||||
@@ -56,9 +82,10 @@ RCT_EXPORT_METHOD(openCameraDialog:(NSDictionary *)config
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UIImagePickerController *imagePicker = [UIImagePickerController new];
|
RCTImagePickerController *imagePicker = [RCTImagePickerController new];
|
||||||
imagePicker.delegate = self;
|
imagePicker.delegate = self;
|
||||||
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
|
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
|
||||||
|
imagePicker.unmirrorFrontFacingCamera = [RCTConvert BOOL:config[@"unmirrorFrontFacingCamera"]];
|
||||||
|
|
||||||
if ([RCTConvert BOOL:config[@"videoMode"]]) {
|
if ([RCTConvert BOOL:config[@"videoMode"]]) {
|
||||||
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
|
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
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user