capacitor-camera-view 2.4.0 → 3.0.0
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.
- package/CapacitorCameraView.podspec +1 -1
- package/Package.swift +1 -1
- package/README.md +341 -49
- package/android/build.gradle +0 -1
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/CameraError.kt +42 -0
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/CameraView.kt +945 -207
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/CameraViewPlugin.kt +87 -43
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/model/BarcodeDetectionResult.kt +28 -2
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/model/CameraDevice.kt +6 -1
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/model/CameraSessionConfiguration.kt +15 -1
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/model/TorchModeState.kt +15 -0
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/model/WebBoundingRect.kt +1 -1
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/utils.kt +73 -19
- package/dist/docs.json +475 -30
- package/dist/esm/definitions.d.ts +478 -26
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/utils.d.ts +59 -15
- package/dist/esm/utils.js +79 -38
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/web.d.ts +191 -13
- package/dist/esm/web.js +624 -141
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +711 -179
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +711 -179
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CameraViewPlugin/CameraError.swift +147 -2
- package/ios/Sources/CameraViewPlugin/CameraEvents.swift +41 -19
- package/ios/Sources/CameraViewPlugin/CameraSessionConfiguration.swift +29 -1
- package/ios/Sources/CameraViewPlugin/CameraViewManager+BarcodeScan.swift +78 -23
- package/ios/Sources/CameraViewPlugin/CameraViewManager+DeferredStart.swift +37 -0
- package/ios/Sources/CameraViewPlugin/CameraViewManager+Focus.swift +131 -0
- package/ios/Sources/CameraViewPlugin/CameraViewManager+Lifecycle.swift +156 -0
- package/ios/Sources/CameraViewPlugin/CameraViewManager+PhotoCapture.swift +73 -41
- package/ios/Sources/CameraViewPlugin/CameraViewManager+ResolutionSelection.swift +57 -0
- package/ios/Sources/CameraViewPlugin/CameraViewManager+Rotation.swift +195 -0
- package/ios/Sources/CameraViewPlugin/CameraViewManager+VideoDataOutput.swift +24 -12
- package/ios/Sources/CameraViewPlugin/CameraViewManager+VideoRecording.swift +22 -73
- package/ios/Sources/CameraViewPlugin/CameraViewManager+Zoom.swift +113 -0
- package/ios/Sources/CameraViewPlugin/CameraViewManager.swift +450 -403
- package/ios/Sources/CameraViewPlugin/CameraViewPlugin.swift +98 -65
- package/ios/Sources/CameraViewPlugin/Utils.swift +61 -7
- package/package.json +25 -9
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import AVFoundation
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
extension AVCaptureDevice {
|
|
5
|
+
/// The zoom factor at which this device's wide-angle lens becomes active.
|
|
6
|
+
///
|
|
7
|
+
/// On a virtual device including the ultra-wide lens, raw zoom `1.0` is the
|
|
8
|
+
/// *ultra-wide* field of view and the wide-angle "1x" the user expects sits
|
|
9
|
+
/// at the first switch-over factor. Every other device returns `1.0`.
|
|
10
|
+
internal var wideAngleZoomFactor: CGFloat {
|
|
11
|
+
guard constituentDevices.contains(where: { $0.deviceType == .builtInUltraWideCamera }),
|
|
12
|
+
let switchOver = virtualDeviceSwitchOverVideoZoomFactors.first
|
|
13
|
+
else {
|
|
14
|
+
return 1.0
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return CGFloat(truncating: switchOver)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// Zoom control. Values are in the active device's own zoom domain, which on a
|
|
22
|
+
/// virtual camera is not the wide-angle-relative domain callers think in — see
|
|
23
|
+
/// `wideAngleZoomFactor` and `applyInitialZoom(_:)`.
|
|
24
|
+
extension CameraViewManager {
|
|
25
|
+
|
|
26
|
+
/// Gets the minimum, maximum, and current zoom factors supported by the current camera device.
|
|
27
|
+
/// The maximum zoom factor is limited to a reasonable value of 10x to prevent excessive zooming
|
|
28
|
+
/// because some devices report very high zoom factors that aren't useful.
|
|
29
|
+
///
|
|
30
|
+
/// - Returns: A tuple containing the minimum, maximum, and current zoom factors.
|
|
31
|
+
public func getSupportedZoomFactors() -> (
|
|
32
|
+
min: CGFloat, max: CGFloat, current: CGFloat
|
|
33
|
+
) {
|
|
34
|
+
guard let currentDevice = currentCameraDevice else {
|
|
35
|
+
return (
|
|
36
|
+
min: 1.0,
|
|
37
|
+
max: 1.0,
|
|
38
|
+
current: 1.0
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let minZoomFactor = currentDevice.minAvailableVideoZoomFactor
|
|
43
|
+
// Scaling by the wide-lens factor keeps the wide-equivalent maximum at
|
|
44
|
+
// 10x on virtual devices whose raw 1.0 is ultra-wide.
|
|
45
|
+
let maxZoomFactor = min(
|
|
46
|
+
currentDevice.activeFormat.videoMaxZoomFactor,
|
|
47
|
+
10.0 * currentDevice.wideAngleZoomFactor
|
|
48
|
+
)
|
|
49
|
+
let currentZoomFactor = currentDevice.videoZoomFactor
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
min: minZoomFactor,
|
|
53
|
+
max: maxZoomFactor,
|
|
54
|
+
current: currentZoomFactor
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// Sets the zoom factor for the current camera device.
|
|
59
|
+
///
|
|
60
|
+
/// - Parameters:
|
|
61
|
+
/// - factor: The zoom factor to set.
|
|
62
|
+
/// - ramp: If enabled the zoom will be applied via ramp
|
|
63
|
+
/// - Throws: An error if the zoom factor cannot be set.
|
|
64
|
+
public func setZoomFactor(_ factor: CGFloat, ramp: Bool = true) throws {
|
|
65
|
+
guard let device = currentCameraDevice else {
|
|
66
|
+
throw CameraError.cameraUnavailable
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let supportedZoomFactors = getSupportedZoomFactors()
|
|
70
|
+
guard
|
|
71
|
+
factor >= supportedZoomFactors.min
|
|
72
|
+
&& factor <= supportedZoomFactors.max
|
|
73
|
+
else {
|
|
74
|
+
throw CameraError.zoomFactorOutOfRange
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
do {
|
|
78
|
+
try device.lockForConfiguration()
|
|
79
|
+
defer { device.unlockForConfiguration() }
|
|
80
|
+
|
|
81
|
+
if ramp {
|
|
82
|
+
device.ramp(toVideoZoomFactor: factor, withRate: 6.0)
|
|
83
|
+
} else {
|
|
84
|
+
device.videoZoomFactor = factor
|
|
85
|
+
}
|
|
86
|
+
} catch {
|
|
87
|
+
throw CameraError.configurationFailed(error)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/// Applies a session's initial zoom factor to the active camera device.
|
|
92
|
+
///
|
|
93
|
+
/// The factor is expressed in the wide-angle domain the caller thinks in, so
|
|
94
|
+
/// on a virtual device whose raw `1.0` is the ultra-wide lens it is scaled
|
|
95
|
+
/// into the device's own zoom domain. Without this the first frame of a
|
|
96
|
+
/// triple-camera session would show the 0.5x ultra-wide field of view.
|
|
97
|
+
///
|
|
98
|
+
/// Must be called on the session queue after the configuration transaction
|
|
99
|
+
/// that set the input has committed, since the supported zoom range is
|
|
100
|
+
/// derived from the device's active format.
|
|
101
|
+
///
|
|
102
|
+
/// - Parameter factor: The requested wide-angle-relative zoom factor.
|
|
103
|
+
/// - Throws: An error if the resulting zoom factor cannot be set.
|
|
104
|
+
internal func applyInitialZoom(_ factor: CGFloat?) throws {
|
|
105
|
+
guard let wideAngle = currentCameraDevice?.wideAngleZoomFactor else { return }
|
|
106
|
+
|
|
107
|
+
if let factor = factor {
|
|
108
|
+
try setZoomFactor(factor * wideAngle, ramp: false)
|
|
109
|
+
} else if wideAngle != 1.0 {
|
|
110
|
+
try setZoomFactor(wideAngle, ramp: false)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|