feat: Add onStarted
and onStopped
events (#2273)
* feat: Add `onStarted` and `onStopped` events * Implement `onStart` for Android * Update CameraSession.kt * Update CameraSessionDelegate.swift
This commit is contained in:
@@ -59,6 +59,8 @@ public final class CameraView: UIView, CameraSessionDelegate {
|
||||
// events
|
||||
@objc var onInitialized: RCTDirectEventBlock?
|
||||
@objc var onError: RCTDirectEventBlock?
|
||||
@objc var onStarted: RCTDirectEventBlock?
|
||||
@objc var onStopped: RCTDirectEventBlock?
|
||||
@objc var onViewReady: RCTDirectEventBlock?
|
||||
@objc var onCodeScanned: RCTDirectEventBlock?
|
||||
// zoom
|
||||
@@ -283,7 +285,23 @@ public final class CameraView: UIView, CameraSessionDelegate {
|
||||
guard let onInitialized = onInitialized else {
|
||||
return
|
||||
}
|
||||
onInitialized([String: Any]())
|
||||
onInitialized([:])
|
||||
}
|
||||
|
||||
func onCameraStarted() {
|
||||
ReactLogger.log(level: .info, message: "Camera started!")
|
||||
guard let onStarted = onStarted else {
|
||||
return
|
||||
}
|
||||
onStarted([:])
|
||||
}
|
||||
|
||||
func onCameraStopped() {
|
||||
ReactLogger.log(level: .info, message: "Camera stopped!")
|
||||
guard let onStopped = onStopped else {
|
||||
return
|
||||
}
|
||||
onStopped([:])
|
||||
}
|
||||
|
||||
func onFrame(sampleBuffer: CMSampleBuffer) {
|
||||
|
@@ -52,6 +52,8 @@ RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString);
|
||||
// Camera View Events
|
||||
RCT_EXPORT_VIEW_PROPERTY(onError, RCTDirectEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onInitialized, RCTDirectEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onStarted, RCTDirectEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onStopped, RCTDirectEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onViewReady, RCTDirectEventBlock);
|
||||
// Code Scanner
|
||||
RCT_EXPORT_VIEW_PROPERTY(codeScannerOptions, NSDictionary);
|
||||
|
@@ -249,8 +249,10 @@ class CameraSession: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate, AVC
|
||||
// Start/Stop session
|
||||
if configuration.isActive {
|
||||
captureSession.startRunning()
|
||||
delegate?.onCameraStarted()
|
||||
} else {
|
||||
captureSession.stopRunning()
|
||||
delegate?.onCameraStopped()
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,6 +21,14 @@ protocol CameraSessionDelegate: AnyObject {
|
||||
Called when the [CameraSession] successfully initializes
|
||||
*/
|
||||
func onSessionInitialized()
|
||||
/**
|
||||
Called when the [CameraSession] starts streaming frames. (isActive=true)
|
||||
*/
|
||||
func onCameraStarted()
|
||||
/**
|
||||
Called when the [CameraSession] stopped streaming frames. (isActive=false)
|
||||
*/
|
||||
func onCameraStopped()
|
||||
/**
|
||||
Called for every frame (if video or frameProcessor is enabled)
|
||||
*/
|
||||
|
Reference in New Issue
Block a user