Merge pull request #244 from corbt/better-orientation-init

Set the right preview orientation before startup
This commit is contained in:
Zack Story 2016-04-02 18:59:08 -07:00
commit 8bb0b32707
2 changed files with 4 additions and 8 deletions

View File

@ -59,6 +59,7 @@ typedef NS_ENUM(NSInteger, RCTCameraTorchMode) {
@property (nonatomic, assign) NSInteger presetCamera;
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer;
@property (nonatomic, assign) NSInteger videoTarget;
@property (nonatomic, assign) NSInteger orientation;
@property (nonatomic, assign) BOOL mirrorImage;
@property (nonatomic, strong) RCTPromiseResolveBlock videoResolve;
@property (nonatomic, strong) RCTPromiseRejectBlock videoReject;

View File

@ -236,18 +236,12 @@ RCT_EXPORT_METHOD(changeFlashMode:(NSInteger)flashMode) {
}
RCT_EXPORT_METHOD(changeOrientation:(NSInteger)orientation) {
[self setOrientation:orientation];
if (self.previewLayer.connection.isVideoOrientationSupported) {
self.previewLayer.connection.videoOrientation = orientation;
}
else {
// Setting videoOrientation isn't yet supported, so we have to wait until
// startSession has finished to set it. Put this in the queue behind.
dispatch_async(self.sessionQueue, ^{
self.previewLayer.connection.videoOrientation = orientation;
});
}
}
RCT_EXPORT_METHOD(changeMirrorImage:(BOOL)mirrorImage) {
self.mirrorImage = mirrorImage;
}
@ -365,6 +359,7 @@ RCT_EXPORT_METHOD(hasFlash:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRej
});
}]];
[self.previewLayer.connection setVideoOrientation:self.orientation];
[self.session startRunning];
});
}