Add start/stopPreview for Camera

This commit is contained in:
Christian Brevik 2017-08-27 14:45:47 +02:00
parent e3fc27711c
commit 1bcf8577a4
No known key found for this signature in database
GPG Key ID: 9ED88DB75E250456
4 changed files with 64 additions and 0 deletions

View File

@ -346,6 +346,14 @@ Returns whether or not the camera has flash capabilities.
Ends the current capture session for video captures. Only applies when the current `captureMode` is `video`.
#### `stopPreview()`
Stops the camera preview from running, and natively will make the current capture session pause.
#### `startPreview()`
Starts the camera preview again if previously stopped.
## Component static methods
#### `iOS` `Camera.checkDeviceAuthorizationStatus(): Promise`

View File

@ -658,6 +658,18 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
}
}
@ReactMethod
public void stopPreview(ReadableMap options) {
Camera camera = RCTCamera.getInstance().acquireCameraInstance(options.getInt("type"));
camera.stopPreview();
}
@ReactMethod
public void startPreview(ReadableMap options) {
Camera camera = RCTCamera.getInstance().acquireCameraInstance(options.getInt("type"));
camera.startPreview();
}
@ReactMethod
public void hasFlash(ReadableMap options, final Promise promise) {
Camera camera = RCTCamera.getInstance().acquireCameraInstance(options.getInt("type"));

View File

@ -236,6 +236,28 @@ export default class Camera extends Component {
return CameraManager.capture(options);
}
startPreview() {
if (Platform.OS === 'android') {
const props = convertNativeProps(this.props);
CameraManager.startPreview({
type: props.type
});
} else {
CameraManager.startPreview();
}
}
stopPreview() {
if (Platform.OS === 'android') {
const props = convertNativeProps(this.props);
CameraManager.stopPreview({
type: props.type
});
} else {
CameraManager.stopPreview();
}
}
stopCapture() {
if (this.state.isRecording) {
this.setState({ isRecording: false });

View File

@ -374,6 +374,28 @@ RCT_EXPORT_METHOD(capture:(NSDictionary *)options
}
}
RCT_EXPORT_METHOD(stopPreview) {
#if TARGET_IPHONE_SIMULATOR
return;
#endif
dispatch_async(self.sessionQueue, ^{
if ([self.session isRunning]) {
[self.session stopRunning];
}
});
}
RCT_EXPORT_METHOD(startPreview) {
#if TARGET_IPHONE_SIMULATOR
return;
#endif
dispatch_async(self.sessionQueue, ^{
if (![self.session isRunning]) {
[self.session startRunning];
}
});
}
RCT_EXPORT_METHOD(stopCapture) {
if (self.movieFileOutput.recording) {
[self.movieFileOutput stopRecording];