Add start/stopPreview for Camera
This commit is contained in:
parent
e3fc27711c
commit
1bcf8577a4
|
@ -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`
|
||||
|
|
|
@ -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"));
|
||||
|
|
22
index.js
22
index.js
|
@ -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 });
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in New Issue