mirror of
https://github.com/status-im/react-native-camera.git
synced 2025-02-23 09:18:07 +00:00
Add flash mode setting
This commit is contained in:
parent
ebe995a177
commit
3dd33d842e
@ -15,7 +15,8 @@ var constants = {
|
||||
Type: NativeModules.CameraManager.Type,
|
||||
CaptureMode: NativeModules.CameraManager.CaptureMode,
|
||||
CaptureTarget: NativeModules.CameraManager.CaptureTarget,
|
||||
Orientation: NativeModules.CameraManager.Orientation
|
||||
Orientation: NativeModules.CameraManager.Orientation,
|
||||
FlashMode: NativeModules.CameraManager.FlashMode
|
||||
};
|
||||
|
||||
var Camera = React.createClass({
|
||||
@ -39,6 +40,10 @@ var Camera = React.createClass({
|
||||
orientation: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.number
|
||||
]),
|
||||
flashMode: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.number
|
||||
])
|
||||
},
|
||||
|
||||
@ -55,7 +60,8 @@ var Camera = React.createClass({
|
||||
type: constants.Type.back,
|
||||
orientation: constants.Orientation.auto,
|
||||
captureMode: constants.CaptureMode.still,
|
||||
captureTarget: constants.CaptureTarget.memory
|
||||
captureTarget: constants.CaptureTarget.memory,
|
||||
flashMode: constants.FlashMode.off,
|
||||
};
|
||||
},
|
||||
|
||||
@ -82,7 +88,8 @@ var Camera = React.createClass({
|
||||
|
||||
var aspect = this.props.aspect,
|
||||
type = this.props.type,
|
||||
orientation = this.props.orientation;
|
||||
orientation = this.props.orientation,
|
||||
flashMode = this.props.flashMode;
|
||||
|
||||
var legacyProps = {
|
||||
aspect: {
|
||||
@ -99,12 +106,18 @@ var Camera = React.createClass({
|
||||
type: {
|
||||
Front: 'front',
|
||||
Back: 'back'
|
||||
},
|
||||
flashMode: {
|
||||
Off: 'off',
|
||||
On: 'on',
|
||||
Auto: 'auto'
|
||||
}
|
||||
};
|
||||
|
||||
var foundLegacyAspect = legacyProps.aspect[aspect];
|
||||
var foundLegacyOrientation = legacyProps.orientation[orientation];
|
||||
var foundLegacyType = legacyProps.type[type];
|
||||
var foundLegacyFlashMode = legacyProps.flashMode[flashMode];
|
||||
|
||||
if (__DEV__) {
|
||||
if (foundLegacyAspect) {
|
||||
@ -137,7 +150,8 @@ var Camera = React.createClass({
|
||||
style,
|
||||
aspect: aspect,
|
||||
type: type,
|
||||
orientation: orientation
|
||||
orientation: orientation,
|
||||
flashMode: flashMode,
|
||||
});
|
||||
|
||||
return <RCTCamera {... nativeProps} />
|
||||
@ -176,7 +190,8 @@ var RCTCamera = createReactNativeComponentClass({
|
||||
validAttributes: merge(ReactNativeViewAttributes.UIView, {
|
||||
aspect: true,
|
||||
type: true,
|
||||
orientation: true
|
||||
orientation: true,
|
||||
flashMode: true,
|
||||
}),
|
||||
uiViewClassName: 'RCTCamera',
|
||||
});
|
||||
|
@ -48,6 +48,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setFlashMode:(NSInteger)flashMode
|
||||
{
|
||||
[self.manager changeFlashMode:flashMode];
|
||||
}
|
||||
|
||||
- (id)initWithManager:(RCTCameraManager*)manager
|
||||
{
|
||||
|
||||
|
@ -32,6 +32,12 @@ typedef NS_ENUM(NSInteger, RCTCameraType) {
|
||||
RCTCameraTypeBack = AVCaptureDevicePositionBack
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger, RCTCameraFlashMode) {
|
||||
RCTCameraFlashModeOff = AVCaptureFlashModeOff,
|
||||
RCTCameraFlashModeOn = AVCaptureFlashModeOn,
|
||||
RCTCameraFlashModeAuto = AVCaptureFlashModeAuto
|
||||
};
|
||||
|
||||
@interface RCTCameraManager : RCTViewManager<AVCaptureMetadataOutputObjectsDelegate>
|
||||
|
||||
@property (nonatomic) dispatch_queue_t sessionQueue;
|
||||
@ -46,6 +52,7 @@ typedef NS_ENUM(NSInteger, RCTCameraType) {
|
||||
- (void)changeAspect:(NSString *)aspect;
|
||||
- (void)changeCamera:(NSInteger)camera;
|
||||
- (void)changeOrientation:(NSInteger)orientation;
|
||||
- (void)changeFlashMode:(NSInteger)flashMode;
|
||||
- (AVCaptureDevice *)deviceWithMediaType:(NSString *)mediaType preferringPosition:(AVCaptureDevicePosition)position;
|
||||
- (void)capture:(NSDictionary*)options callback:(RCTResponseSenderBlock)callback;
|
||||
|
||||
|
@ -20,6 +20,7 @@ RCT_EXPORT_MODULE();
|
||||
RCT_EXPORT_VIEW_PROPERTY(aspect, NSInteger);
|
||||
RCT_EXPORT_VIEW_PROPERTY(type, NSInteger);
|
||||
RCT_EXPORT_VIEW_PROPERTY(orientation, NSInteger);
|
||||
RCT_EXPORT_VIEW_PROPERTY(flashMode, NSInteger);
|
||||
|
||||
- (NSDictionary *)constantsToExport
|
||||
{
|
||||
@ -47,6 +48,11 @@ RCT_EXPORT_VIEW_PROPERTY(orientation, NSInteger);
|
||||
@"landscapeRight": @(RCTCameraOrientationLandscapeRight),
|
||||
@"portrait": @(RCTCameraOrientationPortrait),
|
||||
@"portraitUpsideDown": @(RCTCameraOrientationPortraitUpsideDown)
|
||||
},
|
||||
@"FlashMode": @{
|
||||
@"off": @(RCTCameraFlashModeOff),
|
||||
@"on": @(RCTCameraFlashModeOn),
|
||||
@"auto": @(RCTCameraFlashModeAuto)
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -110,7 +116,7 @@ RCT_EXPORT_VIEW_PROPERTY(orientation, NSInteger);
|
||||
[strongSelf.session startRunning];
|
||||
});
|
||||
}]];
|
||||
|
||||
|
||||
[self.session startRunning];
|
||||
});
|
||||
}
|
||||
@ -126,6 +132,10 @@ RCT_EXPORT_METHOD(checkDeviceAuthorizationStatus:(RCTResponseSenderBlock) callba
|
||||
}];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(changeFlashMode:(NSInteger)flashMode) {
|
||||
AVCaptureDevice *currentCaptureDevice = [self.captureDeviceInput device];
|
||||
[self setFlashMode:flashMode forDevice:currentCaptureDevice];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(changeCamera:(NSInteger)camera) {
|
||||
AVCaptureDevice *currentCaptureDevice = [self.captureDeviceInput device];
|
||||
@ -178,7 +188,7 @@ RCT_EXPORT_METHOD(changeOrientation:(NSInteger)orientation) {
|
||||
RCT_EXPORT_METHOD(capture:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback) {
|
||||
NSInteger captureMode = [[options valueForKey:@"mode"] intValue];
|
||||
NSInteger captureTarget = [[options valueForKey:@"target"] intValue];
|
||||
|
||||
|
||||
if (captureMode == RCTCameraCaptureModeStill) {
|
||||
[self captureStill:captureTarget callback:callback];
|
||||
}
|
||||
@ -196,7 +206,7 @@ RCT_EXPORT_METHOD(capture:(NSDictionary *)options callback:(RCTResponseSenderBlo
|
||||
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
|
||||
UIImage *image = [UIImage imageWithData:imageData];
|
||||
UIImage *rotatedImage = [image resizedImage:CGSizeMake(image.size.width, image.size.height) interpolationQuality:kCGInterpolationDefault];
|
||||
|
||||
|
||||
NSString *responseString;
|
||||
|
||||
if (target == RCTCameraCaptureTargetMemory) {
|
||||
|
11
README.md
11
README.md
@ -149,6 +149,15 @@ Event contains `data` (the data in the barcode) and `bounds` (the rectangle whic
|
||||
|
||||
*TODO: Only emit one event for each barcode scanned.*
|
||||
|
||||
#### `flashMode`
|
||||
|
||||
Values:
|
||||
`Camera.constants.FlashMode.on`,
|
||||
`Camera.constants.FlashMode.off`,
|
||||
`Camera.constants.FlashMode.auto`
|
||||
|
||||
Use the `flashMode` property to specify the camera flash mode.
|
||||
|
||||
## Component 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.
|
||||
@ -164,7 +173,7 @@ This component supports subviews, so if you wish to use the camera view as a bac
|
||||
These are some features I think would be important/beneficial to have included with this module. Pull requests welcome!
|
||||
|
||||
- [ ] Video support
|
||||
- [ ] Flash mode setting
|
||||
- [x] Flash mode setting
|
||||
- [x] Automatic orientation adjustment
|
||||
- [ ] Tap to focus
|
||||
- [ ] Optional facial recognition (w/ ability to style box around face)
|
||||
|
Loading…
x
Reference in New Issue
Block a user