capacitor-plugin-camera-forked 3.0.44 → 3.0.66
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()
|
|
@@ -572,6 +582,15 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
572
582
|
|
|
573
583
|
facingBack = false
|
|
574
584
|
}
|
|
585
|
+
|
|
586
|
+
// Reset video connection orientations after camera switch to prevent rotation issues
|
|
587
|
+
if let connection = self.previewView.videoPreviewLayer.connection {
|
|
588
|
+
connection.videoOrientation = .portrait
|
|
589
|
+
}
|
|
590
|
+
if let videoConnection = self.videoOutput.connection(with: .video) {
|
|
591
|
+
videoConnection.videoOrientation = .portrait
|
|
592
|
+
}
|
|
593
|
+
|
|
575
594
|
if isRunning {
|
|
576
595
|
self.captureSession.startRunning()
|
|
577
596
|
}
|
|
@@ -802,21 +821,26 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
802
821
|
}
|
|
803
822
|
|
|
804
823
|
private func resetFocusIfStuck() {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
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)")
|
|
816
843
|
}
|
|
817
|
-
device.unlockForConfiguration()
|
|
818
|
-
} catch {
|
|
819
|
-
print("Could not reset focus: \(error)")
|
|
820
844
|
}
|
|
821
845
|
}
|
|
822
846
|
|
|
@@ -839,7 +863,8 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
839
863
|
}
|
|
840
864
|
|
|
841
865
|
func focusWithPoint(point: CGPoint) {
|
|
842
|
-
let
|
|
866
|
+
guard let videoInput = self.videoInput else { return }
|
|
867
|
+
let device = videoInput.device
|
|
843
868
|
|
|
844
869
|
let now = Date()
|
|
845
870
|
if now.timeIntervalSince(lastFocusTime) < focusThrottleInterval {
|
|
@@ -916,7 +941,8 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
916
941
|
}
|
|
917
942
|
|
|
918
943
|
private func returnToContinuousFocus() {
|
|
919
|
-
let
|
|
944
|
+
guard let videoInput = self.videoInput else { return }
|
|
945
|
+
let device = videoInput.device
|
|
920
946
|
do {
|
|
921
947
|
try device.lockForConfiguration()
|
|
922
948
|
|
|
@@ -939,47 +965,53 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
939
965
|
|
|
940
966
|
|
|
941
967
|
private func hideFocusIndicatorWithCompletion() {
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
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
|
+
}
|
|
951
979
|
}
|
|
952
980
|
}
|
|
953
981
|
|
|
954
982
|
func showFocusView(at point: CGPoint) {
|
|
955
|
-
|
|
956
|
-
self
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
//
|
|
964
|
-
self.focusView
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
983
|
+
DispatchQueue.main.async { [weak self] in
|
|
984
|
+
guard let self = self else { return }
|
|
985
|
+
|
|
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
|
|
969
1011
|
|
|
970
|
-
//
|
|
971
|
-
//
|
|
1012
|
+
// Skip the animation since the view is invisible
|
|
1013
|
+
// Focus functionality still works, just no visual feedback
|
|
972
1014
|
}
|
|
973
|
-
|
|
974
|
-
self.focusView?.center = point
|
|
975
|
-
self.focusView?.alpha = 0.0 // Keep invisible
|
|
976
|
-
self.focusView?.transform = CGAffineTransform.identity
|
|
977
|
-
self.previewView.addSubview(self.focusView!)
|
|
978
|
-
|
|
979
|
-
self.isFocusAnimating = true
|
|
980
|
-
|
|
981
|
-
// Skip the animation since the view is invisible
|
|
982
|
-
// Focus functionality still works, just no visual feedback
|
|
983
1015
|
}
|
|
984
1016
|
|
|
985
1017
|
@objc func requestCameraPermission(_ call: CAPPluginCall) {
|
package/package.json
CHANGED