Contains fixes for the viewfinder.
This commit is contained in:
parent
488e5327f7
commit
6d7d360f18
|
@ -1,12 +1,10 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import "ViewfinderView.h"
|
||||
|
||||
@class RCTCameraManager;
|
||||
|
||||
@interface RCTCamera : UIView
|
||||
|
||||
@property (nonatomic) ViewfinderView *viewfinder;
|
||||
@property (nonatomic) RCTCameraManager *manager;
|
||||
|
||||
- (id)initWithManager:(RCTCameraManager*)manager;
|
||||
|
|
15
RCTCamera.m
15
RCTCamera.m
|
@ -3,7 +3,6 @@
|
|||
#import "RCTCameraManager.h"
|
||||
#import "RCTLog.h"
|
||||
#import "RCTUtils.h"
|
||||
#import "ViewfinderView.h"
|
||||
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
|
@ -11,7 +10,7 @@
|
|||
|
||||
- (void)setAspect:(NSString *)aspect
|
||||
{
|
||||
[(AVCaptureVideoPreviewLayer *)[_viewfinder layer] setVideoGravity:aspect];
|
||||
[self.manager changeAspect:aspect];
|
||||
}
|
||||
|
||||
- (void)setType:(NSInteger)camera
|
||||
|
@ -31,24 +30,18 @@
|
|||
|
||||
- (id)initWithManager:(RCTCameraManager*)manager
|
||||
{
|
||||
|
||||
if ((self = [super init])) {
|
||||
self.manager = manager;
|
||||
self.viewfinder = [[ViewfinderView alloc] init];
|
||||
self.viewfinder.session = self.manager.session;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSArray *)reactSubviews
|
||||
{
|
||||
NSArray *subviews = @[self.viewfinder];
|
||||
return subviews;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
[super layoutSubviews];
|
||||
[self.viewfinder setFrame:self.bounds];
|
||||
self.manager.previewLayer.frame = self.bounds;
|
||||
[self.layer insertSublayer:self.manager.previewLayer atIndex:0];
|
||||
}
|
||||
|
||||
- (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
@property (nonatomic) AVCaptureStillImageOutput *stillImageOutput;
|
||||
@property (nonatomic) id runtimeErrorHandlingObserver;
|
||||
@property (nonatomic) NSInteger presetCamera;
|
||||
@property (nonatomic) RCTCamera *currentCamera;
|
||||
@property (nonatomic) AVCaptureVideoPreviewLayer *previewLayer;
|
||||
|
||||
- (void)changeAspect:(NSString *)aspect;
|
||||
- (void)changeCamera:(NSInteger)camera;
|
||||
- (void)changeOrientation:(NSInteger)orientation;
|
||||
- (AVCaptureDevice *)deviceWithMediaType:(NSString *)mediaType preferringPosition:(AVCaptureDevicePosition)position;
|
||||
|
|
|
@ -13,8 +13,7 @@ RCT_EXPORT_MODULE();
|
|||
|
||||
- (UIView *)view
|
||||
{
|
||||
self.currentCamera = [[RCTCamera alloc] initWithManager:self];
|
||||
return self.currentCamera;
|
||||
return [[RCTCamera alloc] initWithManager:self];
|
||||
}
|
||||
|
||||
RCT_EXPORT_VIEW_PROPERTY(aspect, NSString);
|
||||
|
@ -45,9 +44,13 @@ RCT_EXPORT_VIEW_PROPERTY(orientation, NSInteger);
|
|||
- (id)init {
|
||||
|
||||
if ((self = [super init])) {
|
||||
|
||||
self.session = [AVCaptureSession new];
|
||||
self.session.sessionPreset = AVCaptureSessionPresetHigh;
|
||||
|
||||
self.previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.session];
|
||||
self.previewLayer.needsDisplayOnBoundsChange = YES;
|
||||
|
||||
self.sessionQueue = dispatch_queue_create("cameraManagerQueue", DISPATCH_QUEUE_SERIAL);
|
||||
|
||||
dispatch_async(self.sessionQueue, ^{
|
||||
|
@ -136,16 +139,19 @@ RCT_EXPORT_METHOD(changeCamera:(NSInteger)camera) {
|
|||
[self.session addInput:self.captureDeviceInput];
|
||||
}
|
||||
|
||||
|
||||
[self.session commitConfiguration];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(changeAspect:(NSString *)aspect) {
|
||||
self.previewLayer.videoGravity = aspect;
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(changeOrientation:(NSInteger)orientation) {
|
||||
((AVCaptureVideoPreviewLayer *)self.currentCamera.viewfinder.layer).connection.videoOrientation = orientation;
|
||||
self.previewLayer.connection.videoOrientation = orientation;
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(takePicture:(RCTResponseSenderBlock)callback) {
|
||||
[[self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:((AVCaptureVideoPreviewLayer *)self.currentCamera.viewfinder.layer).connection.videoOrientation];
|
||||
[[self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:self.previewLayer.connection.videoOrientation];
|
||||
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:[self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
|
||||
|
||||
if (imageDataSampleBuffer)
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
# react-native-camera
|
||||
|
||||
A camera viewport for React Native. This module is currently in the very early stages of development. **Module is blowing up right now with recent changes from the core React Native team. Change is good! But it's breaking this module. Be warned.**
|
||||
A camera viewport for React Native. This module is currently in the very early stages of development.
|
||||
|
||||
## Known Issues
|
||||
Below is a list of known issues. Pull requests are welcome for any of these issues!
|
||||
|
||||
- Viewfinder *does not work*. This is a temporary issue that I'm resolving, but right now it will appear as the module is not working. The camera does in fact work though.
|
||||
- [Camera module may cause app to crash in simulator](https://github.com/lwansbrough/react-native-camera/issues/8)
|
||||
|
||||
## Getting started
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class AVCaptureSession;
|
||||
|
||||
@interface ViewfinderView : UIView
|
||||
|
||||
@property (nonatomic) AVCaptureSession *session;
|
||||
|
||||
@end
|
|
@ -1,21 +0,0 @@
|
|||
#import "ViewfinderView.h"
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
@implementation ViewfinderView
|
||||
|
||||
+ (Class)layerClass
|
||||
{
|
||||
return [AVCaptureVideoPreviewLayer class];
|
||||
}
|
||||
|
||||
- (AVCaptureSession *)session
|
||||
{
|
||||
return [(AVCaptureVideoPreviewLayer *)[self layer] session];
|
||||
}
|
||||
|
||||
- (void)setSession:(AVCaptureSession *)session
|
||||
{
|
||||
[(AVCaptureVideoPreviewLayer *)[self layer] setSession:session];
|
||||
}
|
||||
|
||||
@end
|
|
@ -4,7 +4,7 @@
|
|||
"type" : "git",
|
||||
"url" : "https://github.com/lwansbrough/react-native-camera.git"
|
||||
},
|
||||
"version": "0.0.8",
|
||||
"version": "0.0.9",
|
||||
"description": "A Camera element for React Native",
|
||||
"main": "Camera.ios.js",
|
||||
"author": "Lochlan Wansbrough <lochie@live.com> (http://lwansbrough.com)",
|
||||
|
|
Loading…
Reference in New Issue