Skip to content

Commit

Permalink
feat(ios): add new method isRecording (react-native-camera#1969)
Browse files Browse the repository at this point in the history
* feat: isRecording() to RNCamera which returns boolean

* docs: update RNCamera and typings
  • Loading branch information
svipas authored and n1ru4l committed Dec 5, 2018
1 parent 5797e39 commit 54fedee
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/RNCamera.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ The promise will be fulfilled with an object with some of the following properti

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.

#### `iOS` `isRecording(): Promise<boolean>`

iOS only. Returns a promise. The promise will be fulfilled with a boolean indicating if currently recording is started or stopped.

## Subviews
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.

Expand Down
1 change: 1 addition & 0 deletions ios/RN/RNCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
- (void)onFacesDetected:(NSDictionary *)event;
- (void)onPictureSaved:(NSDictionary *)event;
- (void)onText:(NSDictionary *)event;
- (bool)isRecording;

@end

4 changes: 4 additions & 0 deletions ios/RN/RNCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -1158,4 +1158,8 @@ - (void)stopTextRecognition
self.videoDataOutput = nil;
}

- (bool)isRecording {
return self.movieFileOutput.isRecording;
}

@end
18 changes: 17 additions & 1 deletion ios/RN/RNCameraManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -387,5 +387,21 @@ + (NSDictionary *)faceDetectorConstants
resolve([[[self class] pictureSizes] allKeys]);
}

@end
RCT_EXPORT_METHOD(isRecording:(nonnull NSNumber *)reactTag
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
#if TARGET_IPHONE_SIMULATOR
reject(@"E_IS_RECORDING_FAILED", @"Video recording is not supported on a simulator.", nil);
return;
#endif
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCamera *> *viewRegistry) {
RNCamera *view = viewRegistry[reactTag];
if (![view isKindOfClass:[RNCamera class]]) {
RCTLogError(@"Invalid view returned from registry, expecting RNCamera, got: %@", view);
} else {
resolve(@([view isRecording]));
}
}];
}

@end
4 changes: 4 additions & 0 deletions src/RNCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ export default class Camera extends React.Component<PropsType, StateType> {
CameraManager.pausePreview(this._cameraHandle);
}

isRecording() {
return CameraManager.isRecording(this._cameraHandle);
}

resumePreview() {
CameraManager.resumePreview(this._cameraHandle);
}
Expand Down
7 changes: 5 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { Component, ReactNode } from 'react';
import { ViewProperties } from "react-native";

type Orientation = Readonly<{ auto:any, landscapeLeft:any ,landscapeRight:any, portrait:any, portraitUpsideDown:any}>
type Orientation = Readonly<{ auto: any, landscapeLeft: any, landscapeRight: any, portrait: any, portraitUpsideDown: any }>
type AutoFocus = Readonly<{ on: any, off: any }>;
type FlashMode = Readonly<{ on: any, off: any, torch: any, auto: any }>;
type CameraType = Readonly<{ front: any, back: any }>;
Expand Down Expand Up @@ -73,7 +73,7 @@ export interface RNCameraProps {
pendingAuthorizationView?: JSX.Element;
useCamera2Api?: boolean;
whiteBalance?: keyof WhiteBalance

onCameraReady?(): void;
onMountError?(error: {
message: string
Expand Down Expand Up @@ -232,6 +232,9 @@ export class RNCamera extends Component<RNCameraProps & ViewProperties> {

/** Android only */
getSupportedRatiosAsync(): Promise<string[]>;

/** iOS only */
isRecording(): Promise<boolean>;
}

interface DetectionOptions {
Expand Down

0 comments on commit 54fedee

Please sign in to comment.