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

Commit 54fedee

Browse files
svipasn1ru4l
authored andcommitted
feat(ios): add new method isRecording (#1969)
* feat: isRecording() to RNCamera which returns boolean * docs: update RNCamera and typings
1 parent 5797e39 commit 54fedee

6 files changed

Lines changed: 35 additions & 3 deletions

File tree

docs/RNCamera.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,10 @@ The promise will be fulfilled with an object with some of the following properti
526526

527527
Android only. Returns a promise. The promise will be fulfilled with an object with an array containing strings with all camera aspect ratios supported by the device.
528528

529+
#### `iOS` `isRecording(): Promise<boolean>`
530+
531+
iOS only. Returns a promise. The promise will be fulfilled with a boolean indicating if currently recording is started or stopped.
532+
529533
## Subviews
530534
This component supports subviews, so if you wish to use the camera view as a background or if you want to layout buttons/images/etc. inside the camera then you can do that.
531535

ios/RN/RNCamera.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
- (void)onFacesDetected:(NSDictionary *)event;
7474
- (void)onPictureSaved:(NSDictionary *)event;
7575
- (void)onText:(NSDictionary *)event;
76+
- (bool)isRecording;
7677

7778
@end
7879

ios/RN/RNCamera.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,4 +1158,8 @@ - (void)stopTextRecognition
11581158
self.videoDataOutput = nil;
11591159
}
11601160

1161+
- (bool)isRecording {
1162+
return self.movieFileOutput.isRecording;
1163+
}
1164+
11611165
@end

ios/RN/RNCameraManager.m

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,5 +387,21 @@ + (NSDictionary *)faceDetectorConstants
387387
resolve([[[self class] pictureSizes] allKeys]);
388388
}
389389

390-
@end
390+
RCT_EXPORT_METHOD(isRecording:(nonnull NSNumber *)reactTag
391+
resolver:(RCTPromiseResolveBlock)resolve
392+
rejecter:(RCTPromiseRejectBlock)reject) {
393+
#if TARGET_IPHONE_SIMULATOR
394+
reject(@"E_IS_RECORDING_FAILED", @"Video recording is not supported on a simulator.", nil);
395+
return;
396+
#endif
397+
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCamera *> *viewRegistry) {
398+
RNCamera *view = viewRegistry[reactTag];
399+
if (![view isKindOfClass:[RNCamera class]]) {
400+
RCTLogError(@"Invalid view returned from registry, expecting RNCamera, got: %@", view);
401+
} else {
402+
resolve(@([view isRecording]));
403+
}
404+
}];
405+
}
391406

407+
@end

src/RNCamera.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ export default class Camera extends React.Component<PropsType, StateType> {
317317
CameraManager.pausePreview(this._cameraHandle);
318318
}
319319

320+
isRecording() {
321+
return CameraManager.isRecording(this._cameraHandle);
322+
}
323+
320324
resumePreview() {
321325
CameraManager.resumePreview(this._cameraHandle);
322326
}

types/index.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import { Component, ReactNode } from 'react';
1414
import { ViewProperties } from "react-native";
1515

16-
type Orientation = Readonly<{ auto:any, landscapeLeft:any ,landscapeRight:any, portrait:any, portraitUpsideDown:any}>
16+
type Orientation = Readonly<{ auto: any, landscapeLeft: any, landscapeRight: any, portrait: any, portraitUpsideDown: any }>
1717
type AutoFocus = Readonly<{ on: any, off: any }>;
1818
type FlashMode = Readonly<{ on: any, off: any, torch: any, auto: any }>;
1919
type CameraType = Readonly<{ front: any, back: any }>;
@@ -73,7 +73,7 @@ export interface RNCameraProps {
7373
pendingAuthorizationView?: JSX.Element;
7474
useCamera2Api?: boolean;
7575
whiteBalance?: keyof WhiteBalance
76-
76+
7777
onCameraReady?(): void;
7878
onMountError?(error: {
7979
message: string
@@ -232,6 +232,9 @@ export class RNCamera extends Component<RNCameraProps & ViewProperties> {
232232

233233
/** Android only */
234234
getSupportedRatiosAsync(): Promise<string[]>;
235+
236+
/** iOS only */
237+
isRecording(): Promise<boolean>;
235238
}
236239

237240
interface DetectionOptions {

0 commit comments

Comments
 (0)