A Compose Multiplatform barcode scanning library for Android and iOS.
| Android | iOS |
|---|---|
Add the dependency to your commonMain source set:
implementation("io.github.ismai117:KScan:0.6.0")Android - Uses Google ML Kit for barcode scanning.
iOS - Uses AVFoundation for camera and barcode scanning. Add this to your Info.plist:
<key>NSCameraUsageDescription</key>
<string>Camera access is required for barcode scanning</string>ScannerView(
codeTypes = listOf(BarcodeFormat.FORMAT_QR_CODE, BarcodeFormat.FORMAT_EAN_13)
) { result ->
when (result) {
is BarcodeResult.OnSuccess -> {
println("Barcode: ${result.barcode.data}")
}
is BarcodeResult.OnFailed -> {
println("Error: ${result.exception.message}")
}
BarcodeResult.OnCanceled -> {
println("Canceled")
}
}
}ScannerView(
codeTypes = listOf(BarcodeFormat.FORMAT_QR_CODE),
scannerUiOptions = null
) { result ->
// handle result
}Use ScannerController for torch and zoom:
val scannerController = remember { ScannerController() }
ScannerView(
codeTypes = listOf(BarcodeFormat.FORMAT_ALL_FORMATS),
scannerUiOptions = null,
scannerController = scannerController
) { result ->
// handle result
}
// Torch control
Button(onClick = { scannerController.setTorch(!scannerController.torchEnabled) }) {
Text("Toggle Torch")
}
// Zoom control
Slider(
value = scannerController.zoomRatio,
onValueChange = scannerController::setZoom,
valueRange = 1f..scannerController.maxZoomRatio
)| 1D Barcodes | 2D Barcodes |
|---|---|
| CODE_128 | QR_CODE |
| CODE_39 | AZTEC |
| CODE_93 | DATA_MATRIX |
| CODABAR | PDF417 |
| EAN_13 | |
| EAN_8 | |
| ITF | |
| UPC_A | |
| UPC_E |
Use BarcodeFormat.FORMAT_ALL_FORMATS to scan all supported types.
Copyright 2024 ismai117
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Contributions are welcome! Feel free to open issues or submit pull requests.