Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
WIP: Implement video stabilization mode property for ios (#1606)
Browse files Browse the repository at this point in the history
* feat(rn-camera): implement video stabilization mode property for ios

* feat(rn-camera): export video stabilization values on camera object

* docs(rn-camera): document video stabilization mode feature
  • Loading branch information
n1ru4l authored and sibelius committed Jun 5, 2018
1 parent 9cddb2a commit a090faa
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/RNCamera.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,17 @@ 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` `videoStabilizationMode`

The video stabilization mode used for a video recording. The possible values are:

- `RNCamera.Constants.VideoStabilization['off']`
- `RNCamera.Constants.VideoStabilization['standard']`
- `RNCamera.Constants.VideoStabilization['cinematic']`
- `RNCamera.Constants.VideoStabilization['auto']`

You can read more about each stabilization type here: https://developer.apple.com/documentation/avfoundation/avcapturevideostabilizationmode

### Native Event callbacks props

#### `onCameraReady`
Expand Down
1 change: 1 addition & 0 deletions ios/RN/RNCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
@property (nonatomic, assign) BOOL isReadingBarCodes;
@property (nonatomic, assign) BOOL isDetectingFaces;
@property(assign, nonatomic) AVVideoCodecType videoCodecType;
@property (assign, nonatomic) AVCaptureVideoStabilizationMode videoStabilizationMode;

- (id)initWithBridge:(RCTBridge *)bridge;
- (void)updateType;
Expand Down
7 changes: 7 additions & 0 deletions ios/RN/RNCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ - (void)record:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)resolve r
[self updateSessionAudioIsMuted:!!options[@"mute"]];

AVCaptureConnection *connection = [self.movieFileOutput connectionWithMediaType:AVMediaTypeVideo];
if (self.videoStabilizationMode != nil) {
if (connection.isVideoStabilizationSupported == NO) {
RCTLogWarn(@"%s: Video Stabilization is not supported on this device.", __func__);
} else {
[connection setPreferredVideoStabilizationMode:self.videoStabilizationMode];
}
}
[connection setVideoOrientation:[RNCameraUtils videoOrientationForDeviceOrientation:[[UIDevice currentDevice] orientation]]];

if (options[@"codec"]) {
Expand Down
1 change: 1 addition & 0 deletions ios/RN/RNCameraManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef NS_ENUM(NSInteger, RNCameraVideoResolution) {

+ (NSDictionary *)validBarCodeTypes;
+ (NSDictionary *)validCodecTypes;
+ (NSDictionary *)validVideoStabilizationModes;

@end

13 changes: 12 additions & 1 deletion ios/RN/RNCameraManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ - (NSDictionary *)constantsToExport
},
@"VideoCodec": [[self class] validCodecTypes],
@"BarCodeType" : [[self class] validBarCodeTypes],
@"FaceDetection" : [[self class] faceDetectorConstants]
@"FaceDetection" : [[self class] faceDetectorConstants],
@"VideoStabilization": [[self class] validVideoStabilizationModes]
};
}

Expand All @@ -93,6 +94,16 @@ + (NSDictionary *)validCodecTypes
}
}

+ (NSDictionary *)validVideoStabilizationModes
{
return @{
@"off": AVCaptureVideoStabilizationModeOff,
@"standard": AVCaptureVideoStabilizationModeStandard,
@"cinematic": AVCaptureVideoStabilizationModeCinematic,
@"auto": AVCaptureVideoStabilizationModeAuto
};
}

+ (NSDictionary *)validBarCodeTypes
{
return @{
Expand Down
3 changes: 3 additions & 0 deletions src/RNCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type PropsType = typeof View.props & {
captureAudio?: boolean,
useCamera2Api?: boolean,
playSoundOnCapture?: boolean,
videoStabilizationMode?: string,
pictureSize?: string,
};

Expand Down Expand Up @@ -156,6 +157,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
GoogleVisionBarcodeDetection: CameraManager.GoogleVisionBarcodeDetection,
FaceDetection: CameraManager.FaceDetection,
CameraStatus,
VideoStabilization: CameraManager.VideoStabilization || {},
};

// Values under keys from this object will be transformed to native options
Expand Down Expand Up @@ -198,6 +200,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
captureAudio: PropTypes.bool,
useCamera2Api: PropTypes.bool,
playSoundOnCapture: PropTypes.bool,
videoStabilizationMode: PropTypes.string,
pictureSize: PropTypes.string,
};

Expand Down

0 comments on commit a090faa

Please sign in to comment.