Skip to content
This repository was archived by the owner on Jun 16, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/RNCamera.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ By default a `Camera not authorized` message will be displayed when access to th

By default a <ActivityIndicator> will be displayed while the component is waiting for the user to grant/deny access to the camera, if set displays the passed react element instead of the default one.

#### `iOS` `rectOfInterest`

An `{x: , y:, width:, height: }` object which defines the rect of interst as normalized coordinates from `(0,0)` top left corner to `(1,1)` bottom right corner.

### `iOS` `videoStabilizationMode`

The video stabilization mode used for a video recording. The possible values are:
Expand Down
2 changes: 2 additions & 0 deletions ios/RN/RNCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@property(nonatomic, assign) BOOL canReadText;
@property(nonatomic, assign) BOOL canDetectFaces;
@property(nonatomic, assign) BOOL canDetectBarcodes;
@property(nonatomic, assign) CGRect rectOfInterest;
@property(assign, nonatomic) AVVideoCodecType videoCodecType;
@property(assign, nonatomic)
AVCaptureVideoStabilizationMode videoStabilizationMode;
Expand All @@ -61,6 +62,7 @@
- (void)updateFaceDetectionMode:(id)requestedMode;
- (void)updateFaceDetectionLandmarks:(id)requestedLandmarks;
- (void)updateFaceDetectionClassifications:(id)requestedClassifications;
- (void)updateRectOfInterest;
// google Barcode props
- (void)updateGoogleVisionBarcodeType:(id)requestedTypes;

Expand Down
10 changes: 10 additions & 0 deletions ios/RN/RNCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ - (id)initWithBridge:(RCTBridge *)bridge
self.previewLayer.needsDisplayOnBoundsChange = YES;
#endif
self.paused = NO;
self.rectOfInterest = CGRectMake(0, 0, 1.0, 1.0);
[self changePreviewOrientation:[UIApplication sharedApplication].statusBarOrientation];
[self initializeCaptureSessionInput];
[self startSession];
Expand Down Expand Up @@ -857,6 +858,14 @@ - (void)setupOrDisableBarcodeScanner
[self _updateMetadataObjectsToRecognize];
}

- (void)updateRectOfInterest
{
if (_metadataOutput == nil) {
return;
}
[_metadataOutput setRectOfInterest: _rectOfInterest];
}

- (void)_setupOrDisableMetadataOutput
{
if ([self isReadingBarCodes] && (_metadataOutput == nil || ![self.session.outputs containsObject:_metadataOutput])) {
Expand Down Expand Up @@ -889,6 +898,7 @@ - (void)_updateMetadataObjectsToRecognize
}

[_metadataOutput setMetadataObjectTypes:availableRequestedObjectTypes];
[self updateRectOfInterest];
}

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects
Expand Down
6 changes: 6 additions & 0 deletions ios/RN/RNCameraManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ + (NSDictionary *)barcodeDetectorConstants
[view setupOrDisableTextDetector];
}

RCT_CUSTOM_VIEW_PROPERTY(rectOfInterest, CGRect, RNCamera)
{
[view setRectOfInterest: [RCTConvert CGRect:json]];
[view updateRectOfInterest];
}

RCT_CUSTOM_VIEW_PROPERTY(defaultVideoQuality, NSInteger, RNCamera)
{
[view setDefaultVideoQuality: [NSNumber numberWithInteger:[RCTConvert NSInteger:json]]];
Expand Down
9 changes: 9 additions & 0 deletions src/RNCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ type EventCallbackArgumentsType = {
nativeEvent: Object,
};

type Rect = {
x: number,
y: number,
width: number,
height: number,
};

type PropsType = typeof View.props & {
zoom?: number,
ratio?: string,
Expand Down Expand Up @@ -260,6 +267,7 @@ type PropsType = typeof View.props & {
playSoundOnCapture?: boolean,
videoStabilizationMode?: number | string,
pictureSize?: string,
rectOfInterest: Rect,
};

type StateType = {
Expand Down Expand Up @@ -401,6 +409,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
videoStabilizationMode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
pictureSize: PropTypes.string,
mirrorVideo: PropTypes.bool,
rectOfInterest: PropTypes.any,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use PropTypes.shape

defaultVideoQuality: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};

Expand Down