capacitor-plugin-camera-forked 3.0.55 → 3.0.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -42,20 +42,26 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
// Initialize a camera view for previewing video.
|
|
45
|
-
DispatchQueue.main.
|
|
46
|
-
self
|
|
45
|
+
DispatchQueue.main.async { [weak self] in
|
|
46
|
+
guard let self = self else {
|
|
47
|
+
call.reject("Camera instance deallocated")
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
self.previewView = PreviewView.init(frame: (self.bridge?.viewController?.view.bounds)!)
|
|
47
52
|
self.webView!.superview!.insertSubview(self.previewView, belowSubview: self.webView!)
|
|
48
53
|
|
|
49
54
|
// Only initialize capture session if permission is granted
|
|
50
55
|
if authStatus == .authorized {
|
|
51
|
-
initializeCaptureSession(enableVideoRecording: false)
|
|
56
|
+
self.initializeCaptureSession(enableVideoRecording: false)
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
// Add tap gesture for focus
|
|
55
|
-
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTapToFocus(_:)))
|
|
60
|
+
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.handleTapToFocus(_:)))
|
|
56
61
|
self.previewView.addGestureRecognizer(tapGesture)
|
|
62
|
+
|
|
63
|
+
call.resolve()
|
|
57
64
|
}
|
|
58
|
-
call.resolve()
|
|
59
65
|
}
|
|
60
66
|
|
|
61
67
|
@objc func rotated() {
|
|
@@ -84,10 +90,10 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
84
90
|
return
|
|
85
91
|
}
|
|
86
92
|
|
|
87
|
-
DispatchQueue.global(qos: .userInitiated).async {
|
|
93
|
+
DispatchQueue.global(qos: .userInitiated).async { [weak self] in
|
|
88
94
|
captureSession.startRunning()
|
|
89
95
|
DispatchQueue.main.async {
|
|
90
|
-
self
|
|
96
|
+
self?.triggerOnPlayed()
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
99
|
|
|
@@ -295,7 +301,11 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
295
301
|
}
|
|
296
302
|
|
|
297
303
|
// Enhanced focus before capture for better close-up performance
|
|
298
|
-
let
|
|
304
|
+
guard let videoInput = self.videoInput else {
|
|
305
|
+
self.photoOutput.capturePhoto(with: photoSettings, delegate: self)
|
|
306
|
+
return
|
|
307
|
+
}
|
|
308
|
+
let device = videoInput.device
|
|
299
309
|
if device.isFocusModeSupported(.autoFocus) {
|
|
300
310
|
do {
|
|
301
311
|
try device.lockForConfiguration()
|
|
@@ -803,7 +813,7 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
803
813
|
// Calculate the point in the preview layer's coordinate space
|
|
804
814
|
let previewPoint = CGPoint(x: point.x * previewView.bounds.width,
|
|
805
815
|
y: point.y * previewView.bounds.height)
|
|
806
|
-
showFocusView(at: previewPoint)
|
|
816
|
+
// showFocusView(at: previewPoint)
|
|
807
817
|
call.resolve()
|
|
808
818
|
} else {
|
|
809
819
|
call.reject("Invalid coordinates. Provide normalized x,y values (0.0-1.0)")
|
|
@@ -811,21 +821,26 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
811
821
|
}
|
|
812
822
|
|
|
813
823
|
private func resetFocusIfStuck() {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
824
|
+
DispatchQueue.main.async { [weak self] in
|
|
825
|
+
guard let self = self else { return }
|
|
826
|
+
|
|
827
|
+
// Remove any existing focus indicator
|
|
828
|
+
self.focusView?.removeFromSuperview()
|
|
829
|
+
self.focusCompletionTimer?.invalidate()
|
|
830
|
+
self.isFocusAnimating = false
|
|
831
|
+
|
|
832
|
+
// Reset focus to continuous mode
|
|
833
|
+
guard let videoInput = self.videoInput else { return }
|
|
834
|
+
let device = videoInput.device
|
|
835
|
+
do {
|
|
836
|
+
try device.lockForConfiguration()
|
|
837
|
+
if device.isFocusModeSupported(.continuousAutoFocus) {
|
|
838
|
+
device.focusMode = .continuousAutoFocus
|
|
839
|
+
}
|
|
840
|
+
device.unlockForConfiguration()
|
|
841
|
+
} catch {
|
|
842
|
+
print("Could not reset focus: \(error)")
|
|
825
843
|
}
|
|
826
|
-
device.unlockForConfiguration()
|
|
827
|
-
} catch {
|
|
828
|
-
print("Could not reset focus: \(error)")
|
|
829
844
|
}
|
|
830
845
|
}
|
|
831
846
|
|
|
@@ -844,11 +859,12 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
844
859
|
let convertedPoint = self.previewView.videoPreviewLayer.captureDevicePointConverted(fromLayerPoint: location)
|
|
845
860
|
|
|
846
861
|
focusWithPoint(point: convertedPoint)
|
|
847
|
-
showFocusView(at: location)
|
|
862
|
+
// showFocusView(at: location)
|
|
848
863
|
}
|
|
849
864
|
|
|
850
865
|
func focusWithPoint(point: CGPoint) {
|
|
851
|
-
let
|
|
866
|
+
guard let videoInput = self.videoInput else { return }
|
|
867
|
+
let device = videoInput.device
|
|
852
868
|
|
|
853
869
|
let now = Date()
|
|
854
870
|
if now.timeIntervalSince(lastFocusTime) < focusThrottleInterval {
|
|
@@ -925,7 +941,8 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
925
941
|
}
|
|
926
942
|
|
|
927
943
|
private func returnToContinuousFocus() {
|
|
928
|
-
let
|
|
944
|
+
guard let videoInput = self.videoInput else { return }
|
|
945
|
+
let device = videoInput.device
|
|
929
946
|
do {
|
|
930
947
|
try device.lockForConfiguration()
|
|
931
948
|
|
|
@@ -948,48 +965,54 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
948
965
|
|
|
949
966
|
|
|
950
967
|
private func hideFocusIndicatorWithCompletion() {
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
968
|
+
DispatchQueue.main.async { [weak self] in
|
|
969
|
+
guard let self = self, let focusView = self.focusView else { return }
|
|
970
|
+
|
|
971
|
+
UIView.animate(withDuration: 0.2, animations: {
|
|
972
|
+
focusView.alpha = 0.0
|
|
973
|
+
focusView.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
|
|
974
|
+
}) { _ in
|
|
975
|
+
focusView.removeFromSuperview()
|
|
976
|
+
focusView.transform = CGAffineTransform.identity
|
|
977
|
+
self.isFocusAnimating = false
|
|
978
|
+
}
|
|
960
979
|
}
|
|
961
980
|
}
|
|
962
981
|
|
|
963
|
-
func showFocusView(at point: CGPoint) {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
focusCompletionTimer?.invalidate()
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
// Create focus view if needed - but make it invisible
|
|
970
|
-
if self.focusView == nil {
|
|
971
|
-
self.focusView = UIView(frame: CGRect(x: 0, y: 0, width: 80, height: 80))
|
|
972
|
-
// Make the focus view completely transparent
|
|
973
|
-
self.focusView?.layer.borderColor = UIColor.clear.cgColor
|
|
974
|
-
self.focusView?.layer.borderWidth = 0.0
|
|
975
|
-
self.focusView?.layer.cornerRadius = 40
|
|
976
|
-
self.focusView?.backgroundColor = .clear
|
|
977
|
-
self.focusView?.alpha = 0.0
|
|
982
|
+
// func showFocusView(at point: CGPoint) {
|
|
983
|
+
// DispatchQueue.main.async { [weak self] in
|
|
984
|
+
// guard let self = self else { return }
|
|
978
985
|
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
986
|
+
// if self.isFocusAnimating {
|
|
987
|
+
// self.focusView?.removeFromSuperview()
|
|
988
|
+
// self.focusCompletionTimer?.invalidate()
|
|
989
|
+
// }
|
|
990
|
+
|
|
991
|
+
// // Create focus view if needed - but make it invisible
|
|
992
|
+
// if self.focusView == nil {
|
|
993
|
+
// self.focusView = UIView(frame: CGRect(x: 0, y: 0, width: 80, height: 80))
|
|
994
|
+
// // Make the focus view completely transparent
|
|
995
|
+
// self.focusView?.layer.borderColor = UIColor.clear.cgColor
|
|
996
|
+
// self.focusView?.layer.borderWidth = 0.0
|
|
997
|
+
// self.focusView?.layer.cornerRadius = 40
|
|
998
|
+
// self.focusView?.backgroundColor = .clear
|
|
999
|
+
// self.focusView?.alpha = 0.0
|
|
1000
|
+
|
|
1001
|
+
// // Remove the inner circle to make it completely invisible
|
|
1002
|
+
// // No inner circle added
|
|
1003
|
+
// }
|
|
1004
|
+
|
|
1005
|
+
// self.focusView?.center = point
|
|
1006
|
+
// self.focusView?.alpha = 0.0 // Keep invisible
|
|
1007
|
+
// self.focusView?.transform = CGAffineTransform.identity
|
|
1008
|
+
// self.previewView.addSubview(self.focusView!)
|
|
1009
|
+
|
|
1010
|
+
// self.isFocusAnimating = true
|
|
1011
|
+
|
|
1012
|
+
// // Skip the animation since the view is invisible
|
|
1013
|
+
// // Focus functionality still works, just no visual feedback
|
|
1014
|
+
// }
|
|
1015
|
+
// }
|
|
993
1016
|
|
|
994
1017
|
@objc func requestCameraPermission(_ call: CAPPluginCall) {
|
|
995
1018
|
AVCaptureDevice.requestAccess(for: .video) { granted in
|
package/package.json
CHANGED