KScan
Compose Multiplatform Barcode Scanning
Install / Use
/learn @ismai117/KScanREADME
KScan
A Compose Multiplatform barcode scanning library for Android, iOS and Desktop.
| Android | iOS | Desktop | |---------|-----|---------| | <img src="https://github.com/user-attachments/assets/9bce6d77-4028-4a45-b4a2-ad78e79cc0cd" height="600"/> | <img src="https://github.com/user-attachments/assets/36900489-dea0-456b-bd17-00fcb49f9701" height="600"/> | <img src="https://github.com/user-attachments/assets/d812a038-2a67-416c-a7a4-f1fcd37bd1f5" height="600"/> |
Installation
Add the dependency to your commonMain source set:
implementation("io.github.ismai117:KScan:$version")
Platform Setup
Android - Uses Google ML Kit for barcode scanning.
iOS - Uses AVFoundation for camera and barcode scanning.
Windows / macOS / Linux - Uses JavaCV for camera and ZXing for barcode scanning.
Permissions
Android, iOS, macOS - Before displaying the ScannerView, your application must request and be granted camera permissions by the operating system. On iOS & macOS, add this to your Info.plist:
<key>NSCameraUsageDescription</key>
<string>Camera access is required for barcode scanning</string>
Usage
Basic
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")
}
}
}
Without Default UI
ScannerView(
codeTypes = listOf(BarcodeFormat.FORMAT_QR_CODE),
scannerUiOptions = null
) { result ->
// handle result
}
Custom Controls
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
)
Supported Formats
| 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.
License
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
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
Related Skills
node-connect
335.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
82.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
335.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
82.5kCommit, push, and open a PR
