Add the `mirrorImage` prop will will mirror the resulting image when true.
This commit is contained in:
parent
63cfb65e43
commit
1406e0630f
|
@ -82,6 +82,7 @@ export default class Camera extends Component {
|
||||||
onBarCodeRead: PropTypes.func,
|
onBarCodeRead: PropTypes.func,
|
||||||
onFocusChanged: PropTypes.func,
|
onFocusChanged: PropTypes.func,
|
||||||
onZoomChanged: PropTypes.func,
|
onZoomChanged: PropTypes.func,
|
||||||
|
mirrorImage: PropTypes.bool,
|
||||||
orientation: PropTypes.oneOfType([
|
orientation: PropTypes.oneOfType([
|
||||||
PropTypes.string,
|
PropTypes.string,
|
||||||
PropTypes.number
|
PropTypes.number
|
||||||
|
@ -106,7 +107,8 @@ export default class Camera extends Component {
|
||||||
captureQuality: CameraManager.CaptureQuality.high,
|
captureQuality: CameraManager.CaptureQuality.high,
|
||||||
defaultOnFocusComponent: true,
|
defaultOnFocusComponent: true,
|
||||||
flashMode: CameraManager.FlashMode.off,
|
flashMode: CameraManager.FlashMode.off,
|
||||||
torchMode: CameraManager.TorchMode.off
|
torchMode: CameraManager.TorchMode.off,
|
||||||
|
mirrorImage: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
static checkDeviceAuthorizationStatus = CameraManager.checkDeviceAuthorizationStatus;
|
static checkDeviceAuthorizationStatus = CameraManager.checkDeviceAuthorizationStatus;
|
||||||
|
|
|
@ -224,6 +224,10 @@ By default, `onZoomChanged` is not defined and pinch-to-zoom is disabled.
|
||||||
|
|
||||||
If set to `true`, the device will not sleep while the camera preview is visible. This mimics the behavior of the default camera app, which keeps the device awake while open.
|
If set to `true`, the device will not sleep while the camera preview is visible. This mimics the behavior of the default camera app, which keeps the device awake while open.
|
||||||
|
|
||||||
|
#### `iOS` `mirrorImage`
|
||||||
|
|
||||||
|
If set to `true`, the image returned will be mirrored..
|
||||||
|
|
||||||
## Component instance methods
|
## Component instance methods
|
||||||
|
|
||||||
You can access component methods by adding a `ref` (ie. `ref="camera"`) prop to your `<Camera>` element, then you can use `this.refs.camera.capture(cb)`, etc. inside your component.
|
You can access component methods by adding a `ref` (ie. `ref="camera"`) prop to your `<Camera>` element, then you can use `this.refs.camera.capture(cb)`, etc. inside your component.
|
||||||
|
|
|
@ -68,6 +68,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setMirrorImage:(BOOL)mirrorImage
|
||||||
|
{
|
||||||
|
[self.manager changeMirrorImage:mirrorImage];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setFlashMode:(NSInteger)flashMode
|
- (void)setFlashMode:(NSInteger)flashMode
|
||||||
{
|
{
|
||||||
[self.manager changeFlashMode:flashMode];
|
[self.manager changeFlashMode:flashMode];
|
||||||
|
|
|
@ -59,6 +59,7 @@ typedef NS_ENUM(NSInteger, RCTCameraTorchMode) {
|
||||||
@property (nonatomic, assign) NSInteger presetCamera;
|
@property (nonatomic, assign) NSInteger presetCamera;
|
||||||
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer;
|
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer;
|
||||||
@property (nonatomic, assign) NSInteger videoTarget;
|
@property (nonatomic, assign) NSInteger videoTarget;
|
||||||
|
@property (nonatomic, assign) BOOL mirrorImage;
|
||||||
@property (nonatomic, strong) RCTPromiseResolveBlock videoResolve;
|
@property (nonatomic, strong) RCTPromiseResolveBlock videoResolve;
|
||||||
@property (nonatomic, strong) RCTPromiseRejectBlock videoReject;
|
@property (nonatomic, strong) RCTPromiseRejectBlock videoReject;
|
||||||
@property (nonatomic, strong) RCTCamera *camera;
|
@property (nonatomic, strong) RCTCamera *camera;
|
||||||
|
@ -67,6 +68,7 @@ typedef NS_ENUM(NSInteger, RCTCameraTorchMode) {
|
||||||
- (void)changeAspect:(NSString *)aspect;
|
- (void)changeAspect:(NSString *)aspect;
|
||||||
- (void)changeCamera:(NSInteger)camera;
|
- (void)changeCamera:(NSInteger)camera;
|
||||||
- (void)changeOrientation:(NSInteger)orientation;
|
- (void)changeOrientation:(NSInteger)orientation;
|
||||||
|
- (void)changeMirrorImage:(BOOL)mirrorImage;
|
||||||
- (void)changeFlashMode:(NSInteger)flashMode;
|
- (void)changeFlashMode:(NSInteger)flashMode;
|
||||||
- (void)changeTorchMode:(NSInteger)torchMode;
|
- (void)changeTorchMode:(NSInteger)torchMode;
|
||||||
- (AVCaptureDevice *)deviceWithMediaType:(NSString *)mediaType preferringPosition:(AVCaptureDevicePosition)position;
|
- (AVCaptureDevice *)deviceWithMediaType:(NSString *)mediaType preferringPosition:(AVCaptureDevicePosition)position;
|
||||||
|
|
|
@ -31,6 +31,7 @@ RCT_EXPORT_VIEW_PROPERTY(orientation, NSInteger);
|
||||||
RCT_EXPORT_VIEW_PROPERTY(flashMode, NSInteger);
|
RCT_EXPORT_VIEW_PROPERTY(flashMode, NSInteger);
|
||||||
RCT_EXPORT_VIEW_PROPERTY(torchMode, NSInteger);
|
RCT_EXPORT_VIEW_PROPERTY(torchMode, NSInteger);
|
||||||
RCT_EXPORT_VIEW_PROPERTY(keepAwake, BOOL);
|
RCT_EXPORT_VIEW_PROPERTY(keepAwake, BOOL);
|
||||||
|
RCT_EXPORT_VIEW_PROPERTY(mirrorImage, BOOL);
|
||||||
|
|
||||||
- (NSDictionary *)constantsToExport
|
- (NSDictionary *)constantsToExport
|
||||||
{
|
{
|
||||||
|
@ -143,6 +144,7 @@ RCT_EXPORT_VIEW_PROPERTY(onZoomChanged, BOOL)
|
||||||
- (id)init {
|
- (id)init {
|
||||||
|
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
|
self.mirrorImage = false;
|
||||||
|
|
||||||
self.session = [AVCaptureSession new];
|
self.session = [AVCaptureSession new];
|
||||||
|
|
||||||
|
@ -246,6 +248,10 @@ RCT_EXPORT_METHOD(changeOrientation:(NSInteger)orientation) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RCT_EXPORT_METHOD(changeMirrorImage:(BOOL)mirrorImage) {
|
||||||
|
self.mirrorImage = mirrorImage;
|
||||||
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(changeTorchMode:(NSInteger)torchMode) {
|
RCT_EXPORT_METHOD(changeTorchMode:(NSInteger)torchMode) {
|
||||||
AVCaptureDevice *device = [self.videoCaptureDeviceInput device];
|
AVCaptureDevice *device = [self.videoCaptureDeviceInput device];
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
|
@ -579,6 +585,12 @@ RCT_EXPORT_METHOD(hasFlash:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRej
|
||||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||||
CGContextRef bmContext = CGBitmapContextCreate(NULL, rotatedRect.size.width, rotatedRect.size.height, 8, 0, colorSpace, (CGBitmapInfo) kCGImageAlphaPremultipliedFirst);
|
CGContextRef bmContext = CGBitmapContextCreate(NULL, rotatedRect.size.width, rotatedRect.size.height, 8, 0, colorSpace, (CGBitmapInfo) kCGImageAlphaPremultipliedFirst);
|
||||||
|
|
||||||
|
if (self.mirrorImage) {
|
||||||
|
CGAffineTransform transform = CGAffineTransformMakeTranslation(rotatedRect.size.width, 0.0);
|
||||||
|
transform = CGAffineTransformScale(transform, -1.0, 1.0);
|
||||||
|
CGContextConcatCTM(bmContext, transform);
|
||||||
|
}
|
||||||
|
|
||||||
CGContextSetAllowsAntialiasing(bmContext, TRUE);
|
CGContextSetAllowsAntialiasing(bmContext, TRUE);
|
||||||
CGContextSetInterpolationQuality(bmContext, kCGInterpolationNone);
|
CGContextSetInterpolationQuality(bmContext, kCGInterpolationNone);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue