capacitor-camera-view 1.1.0 → 1.2.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/README.md +70 -1
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/CameraError.kt +9 -0
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/CameraView.kt +72 -29
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/CameraViewPlugin.kt +43 -0
- package/dist/docs.json +140 -0
- package/dist/esm/definitions.d.ts +66 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +13 -1
- package/dist/esm/web.js +21 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +21 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +21 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CameraViewPlugin/CameraError.swift +3 -0
- package/ios/Sources/CameraViewPlugin/CameraViewManager+BarcodeScan.swift +9 -0
- package/ios/Sources/CameraViewPlugin/CameraViewManager.swift +50 -0
- package/ios/Sources/CameraViewPlugin/CameraViewPlugin.swift +40 -1
- package/package.json +1 -1
|
@@ -40,6 +40,15 @@ extension CameraViewManager: AVCaptureMetadataOutputObjectsDelegate {
|
|
|
40
40
|
]
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/// Remove the metadata output if in case it is already configured, e.g. because
|
|
44
|
+
/// the camera is restarted with a diffrent setting where barcode detection was disabled
|
|
45
|
+
/// again
|
|
46
|
+
internal func removeMetadataOutput() {
|
|
47
|
+
if let metadataOutput = captureSession.outputs.first(where: { $0 is AVCaptureMetadataOutput }) {
|
|
48
|
+
captureSession.removeOutput(metadataOutput)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
43
52
|
/// Delegate method called when metadata objects are detected in the camera feed
|
|
44
53
|
///
|
|
45
54
|
/// This method processes barcode data detected in the camera stream. When a barcode is detected,
|
|
@@ -29,6 +29,10 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
|
|
|
29
29
|
/// Currently selected flash mode.
|
|
30
30
|
private var flashMode: AVCaptureDevice.FlashMode = .auto
|
|
31
31
|
|
|
32
|
+
/// Currently selected torch mode and level.
|
|
33
|
+
private var torchEnabled: Bool = false
|
|
34
|
+
private var torchLevel: Float = 1.0
|
|
35
|
+
|
|
32
36
|
/// Reference to the blur overlay view that is shown when switching to the triple camera in order to have a smooth transition
|
|
33
37
|
private var blurOverlayView: UIVisualEffectView?
|
|
34
38
|
|
|
@@ -232,6 +236,48 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
|
|
|
232
236
|
return [.off]
|
|
233
237
|
}
|
|
234
238
|
|
|
239
|
+
/// Checks if torch is available on the current camera device.
|
|
240
|
+
///
|
|
241
|
+
/// - Returns: True if torch is available, false otherwise
|
|
242
|
+
public func isTorchAvailable() -> Bool {
|
|
243
|
+
guard let camera = currentCameraDevice else { return false }
|
|
244
|
+
return camera.hasTorch
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/// Gets the current torch mode and level.
|
|
248
|
+
///
|
|
249
|
+
/// - Returns: A tuple containing the torch enabled state and level
|
|
250
|
+
public func getTorchMode() -> (enabled: Bool, level: Float) {
|
|
251
|
+
return (torchEnabled, torchLevel)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/// Sets the torch mode and level for the currently active camera device.
|
|
255
|
+
///
|
|
256
|
+
/// - Parameters:
|
|
257
|
+
/// - enabled: Whether to enable or disable the torch
|
|
258
|
+
/// - level: The torch intensity level (0.0 to 1.0)
|
|
259
|
+
/// - Throws: An error if the torch mode cannot be set or is not supported.
|
|
260
|
+
public func setTorchMode(enabled: Bool, level: Float = 1.0) throws {
|
|
261
|
+
guard let camera = currentCameraDevice else { throw CameraError.cameraUnavailable }
|
|
262
|
+
guard camera.hasTorch else { throw CameraError.torchUnavailable }
|
|
263
|
+
|
|
264
|
+
do {
|
|
265
|
+
try camera.lockForConfiguration()
|
|
266
|
+
defer { camera.unlockForConfiguration() }
|
|
267
|
+
|
|
268
|
+
if enabled && level > 0.0 {
|
|
269
|
+
try camera.setTorchModeOn(level: level)
|
|
270
|
+
} else {
|
|
271
|
+
camera.torchMode = .off
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
torchEnabled = enabled && level > 0.0
|
|
275
|
+
torchLevel = level
|
|
276
|
+
} catch {
|
|
277
|
+
throw CameraError.configurationFailed(error)
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
235
281
|
/// Gets the minimum, maximum, and current zoom factors supported by the current camera device.
|
|
236
282
|
/// The maximum zoom factor is limited to a reasonable value of 10x to prevent excessive zooming
|
|
237
283
|
/// because some devices report very high zoom factors that aren't useful.
|
|
@@ -318,6 +364,10 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
|
|
|
318
364
|
// Setup metadata output for QR code scanning if enabled
|
|
319
365
|
if configuration.enableBarcodeDetection {
|
|
320
366
|
try setupMetadataOutput()
|
|
367
|
+
} else {
|
|
368
|
+
// Remove the metadata output in case it already existed for the
|
|
369
|
+
// capture session
|
|
370
|
+
removeMetadataOutput()
|
|
321
371
|
}
|
|
322
372
|
|
|
323
373
|
// Set the initial zoom factor if specified
|
|
@@ -36,6 +36,9 @@ public class CameraViewPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
36
36
|
CAPPluginMethod(name: "getFlashMode", returnType: CAPPluginReturnPromise),
|
|
37
37
|
CAPPluginMethod(name: "getSupportedFlashModes", returnType: CAPPluginReturnPromise),
|
|
38
38
|
CAPPluginMethod(name: "setFlashMode", returnType: CAPPluginReturnPromise),
|
|
39
|
+
CAPPluginMethod(name: "isTorchAvailable", returnType: CAPPluginReturnPromise),
|
|
40
|
+
CAPPluginMethod(name: "getTorchMode", returnType: CAPPluginReturnPromise),
|
|
41
|
+
CAPPluginMethod(name: "setTorchMode", returnType: CAPPluginReturnPromise),
|
|
39
42
|
CAPPluginMethod(name: "checkPermissions", returnType: CAPPluginReturnPromise),
|
|
40
43
|
CAPPluginMethod(name: "requestPermissions", returnType: CAPPluginReturnPromise)
|
|
41
44
|
]
|
|
@@ -259,7 +262,7 @@ public class CameraViewPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
259
262
|
let flashMode = implementation.getFlashMode()
|
|
260
263
|
|
|
261
264
|
call.resolve([
|
|
262
|
-
"flashMode": flashMode
|
|
265
|
+
"flashMode": flashModeToStrMap[flashMode] ?? "off"
|
|
263
266
|
])
|
|
264
267
|
}
|
|
265
268
|
|
|
@@ -291,6 +294,42 @@ public class CameraViewPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
291
294
|
}
|
|
292
295
|
}
|
|
293
296
|
|
|
297
|
+
@objc func isTorchAvailable(_ call: CAPPluginCall) {
|
|
298
|
+
let available = implementation.isTorchAvailable()
|
|
299
|
+
call.resolve([
|
|
300
|
+
"available": available
|
|
301
|
+
])
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
@objc func getTorchMode(_ call: CAPPluginCall) {
|
|
305
|
+
let torchState = implementation.getTorchMode()
|
|
306
|
+
call.resolve([
|
|
307
|
+
"enabled": torchState.enabled,
|
|
308
|
+
"level": torchState.level
|
|
309
|
+
])
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
@objc func setTorchMode(_ call: CAPPluginCall) {
|
|
313
|
+
guard let enabled = call.getBool("enabled") else {
|
|
314
|
+
call.reject("Enabled parameter is required")
|
|
315
|
+
return
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
let level = call.getFloat("level") ?? 1.0
|
|
319
|
+
|
|
320
|
+
guard level >= 0.0 && level <= 1.0 else {
|
|
321
|
+
call.reject("Level must be between 0.0 and 1.0")
|
|
322
|
+
return
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
do {
|
|
326
|
+
try implementation.setTorchMode(enabled: enabled, level: level)
|
|
327
|
+
call.resolve()
|
|
328
|
+
} catch {
|
|
329
|
+
call.reject("Failed to set torch mode", nil, error)
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
294
333
|
@objc override public func checkPermissions(_ call: CAPPluginCall) {
|
|
295
334
|
let cameraState: String
|
|
296
335
|
|
package/package.json
CHANGED