capacitor-camera-view 1.1.1 → 1.2.1
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/Package.swift +1 -1
- 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 +79 -29
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/CameraViewPlugin.kt +40 -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.swift +44 -0
- package/ios/Sources/CameraViewPlugin/CameraViewPlugin.swift +40 -1
- package/package.json +1 -1
|
@@ -232,6 +232,50 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
|
|
|
232
232
|
return [.off]
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
/// Checks if torch is available on the current camera device.
|
|
236
|
+
///
|
|
237
|
+
/// - Returns: True if torch is available, false otherwise
|
|
238
|
+
public func isTorchAvailable() -> Bool {
|
|
239
|
+
guard let camera = currentCameraDevice else { return false }
|
|
240
|
+
return camera.hasTorch
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/// Gets the current torch mode and level.
|
|
244
|
+
///
|
|
245
|
+
/// - Returns: A tuple containing the torch enabled state and level
|
|
246
|
+
public func getTorchMode() -> (enabled: Bool, level: Float) {
|
|
247
|
+
guard let camera = currentCameraDevice else { return (false, 0.0) }
|
|
248
|
+
|
|
249
|
+
let isEnabled = camera.torchMode == .on
|
|
250
|
+
let level = camera.torchLevel
|
|
251
|
+
|
|
252
|
+
return (isEnabled, level)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/// Sets the torch mode and level for the currently active camera device.
|
|
256
|
+
///
|
|
257
|
+
/// - Parameters:
|
|
258
|
+
/// - enabled: Whether to enable or disable the torch
|
|
259
|
+
/// - level: The torch intensity level (0.0 to 1.0)
|
|
260
|
+
/// - Throws: An error if the torch mode cannot be set or is not supported.
|
|
261
|
+
public func setTorchMode(enabled: Bool, level: Float = 1.0) throws {
|
|
262
|
+
guard let camera = currentCameraDevice else { throw CameraError.cameraUnavailable }
|
|
263
|
+
guard camera.hasTorch else { throw CameraError.torchUnavailable }
|
|
264
|
+
|
|
265
|
+
do {
|
|
266
|
+
try camera.lockForConfiguration()
|
|
267
|
+
defer { camera.unlockForConfiguration() }
|
|
268
|
+
|
|
269
|
+
if enabled && level > 0.0 {
|
|
270
|
+
try camera.setTorchModeOn(level: level)
|
|
271
|
+
} else {
|
|
272
|
+
camera.torchMode = .off
|
|
273
|
+
}
|
|
274
|
+
} catch {
|
|
275
|
+
throw CameraError.configurationFailed(error)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
235
279
|
/// Gets the minimum, maximum, and current zoom factors supported by the current camera device.
|
|
236
280
|
/// The maximum zoom factor is limited to a reasonable value of 10x to prevent excessive zooming
|
|
237
281
|
/// because some devices report very high zoom factors that aren't useful.
|
|
@@ -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