capacitor-camera-view 1.2.0 → 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/android/src/main/java/com/michaelwolz/capacitorcameraview/CameraView.kt +11 -4
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/CameraViewPlugin.kt +1 -4
- package/ios/Sources/CameraViewPlugin/CameraViewManager.swift +6 -8
- package/package.json +1 -1
package/Package.swift
CHANGED
|
@@ -10,7 +10,7 @@ let package = Package(
|
|
|
10
10
|
targets: ["CameraViewPlugin"])
|
|
11
11
|
],
|
|
12
12
|
dependencies: [
|
|
13
|
-
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.2
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.4.2")
|
|
14
14
|
],
|
|
15
15
|
targets: [
|
|
16
16
|
.target(
|
|
@@ -19,6 +19,7 @@ import androidx.camera.core.ImageAnalysis
|
|
|
19
19
|
import androidx.camera.core.ImageCapture
|
|
20
20
|
import androidx.camera.core.ImageCaptureException
|
|
21
21
|
import androidx.camera.core.ImageProxy
|
|
22
|
+
import androidx.camera.core.TorchState
|
|
22
23
|
import androidx.camera.core.resolutionselector.AspectRatioStrategy
|
|
23
24
|
import androidx.camera.core.resolutionselector.ResolutionSelector
|
|
24
25
|
import androidx.camera.mlkit.vision.MlKitAnalyzer
|
|
@@ -55,7 +56,6 @@ class CameraView(plugin: Plugin) {
|
|
|
55
56
|
// Camera state
|
|
56
57
|
private var currentCameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
|
|
57
58
|
private var currentFlashMode: Int = ImageCapture.FLASH_MODE_OFF
|
|
58
|
-
private var isTorchEnabled: Boolean = false
|
|
59
59
|
|
|
60
60
|
// Plugin context
|
|
61
61
|
private var lifecycleOwner: LifecycleOwner? = null
|
|
@@ -416,8 +416,16 @@ class CameraView(plugin: Plugin) {
|
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
/** Get the current torch mode */
|
|
419
|
-
fun getTorchMode(
|
|
420
|
-
|
|
419
|
+
fun getTorchMode(callback: (Boolean) -> Unit) {
|
|
420
|
+
mainHandler.post {
|
|
421
|
+
val cameraInfo = cameraController?.cameraInfo
|
|
422
|
+
?: run {
|
|
423
|
+
callback(false)
|
|
424
|
+
return@post
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
callback(cameraInfo.torchState.value == TorchState.ON)
|
|
428
|
+
}
|
|
421
429
|
}
|
|
422
430
|
|
|
423
431
|
/** Set the torch mode */
|
|
@@ -437,7 +445,6 @@ class CameraView(plugin: Plugin) {
|
|
|
437
445
|
}
|
|
438
446
|
|
|
439
447
|
controller.cameraControl?.enableTorch(enabled)
|
|
440
|
-
isTorchEnabled = enabled
|
|
441
448
|
callback?.invoke(null)
|
|
442
449
|
} catch (e: Exception) {
|
|
443
450
|
callback?.invoke(e)
|
|
@@ -220,8 +220,7 @@ class CameraViewPlugin : Plugin() {
|
|
|
220
220
|
|
|
221
221
|
@PluginMethod
|
|
222
222
|
fun getTorchMode(call: PluginCall) {
|
|
223
|
-
|
|
224
|
-
val enabled = implementation.getTorchMode()
|
|
223
|
+
implementation.getTorchMode { enabled ->
|
|
225
224
|
call.resolve(JSObject().apply {
|
|
226
225
|
put("enabled", enabled)
|
|
227
226
|
put(
|
|
@@ -230,8 +229,6 @@ class CameraViewPlugin : Plugin() {
|
|
|
230
229
|
if (enabled) 1.0f else 0.0f
|
|
231
230
|
)
|
|
232
231
|
})
|
|
233
|
-
} catch (e: Exception) {
|
|
234
|
-
call.reject("Failed to get torch mode: ${e.localizedMessage}", e)
|
|
235
232
|
}
|
|
236
233
|
}
|
|
237
234
|
|
|
@@ -29,10 +29,6 @@ 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
|
-
|
|
36
32
|
/// Reference to the blur overlay view that is shown when switching to the triple camera in order to have a smooth transition
|
|
37
33
|
private var blurOverlayView: UIVisualEffectView?
|
|
38
34
|
|
|
@@ -248,7 +244,12 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
|
|
|
248
244
|
///
|
|
249
245
|
/// - Returns: A tuple containing the torch enabled state and level
|
|
250
246
|
public func getTorchMode() -> (enabled: Bool, level: Float) {
|
|
251
|
-
return (
|
|
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)
|
|
252
253
|
}
|
|
253
254
|
|
|
254
255
|
/// Sets the torch mode and level for the currently active camera device.
|
|
@@ -270,9 +271,6 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
|
|
|
270
271
|
} else {
|
|
271
272
|
camera.torchMode = .off
|
|
272
273
|
}
|
|
273
|
-
|
|
274
|
-
torchEnabled = enabled && level > 0.0
|
|
275
|
-
torchLevel = level
|
|
276
274
|
} catch {
|
|
277
275
|
throw CameraError.configurationFailed(error)
|
|
278
276
|
}
|
package/package.json
CHANGED