https://github.com/ismai117/KScan
Compose Multiplatform Barcode Scanning
https://github.com/ismai117/KScan
Last synced: 3 months ago
JSON representation
Compose Multiplatform Barcode Scanning
- Host: GitHub
- URL: https://github.com/ismai117/KScan
- Owner: ismai117
- License: apache-2.0
- Created: 2024-11-04T23:49:30.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-19T20:09:29.000Z (4 months ago)
- Last Synced: 2024-12-19T20:27:09.746Z (4 months ago)
- Language: Kotlin
- Size: 61.3 MB
- Stars: 75
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- kmp-awesome - kScan - Barcode Scanner (Libraries / 📱 Device)
README
[](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
[](https://opensource.org/licenses/Apache-2.0)
[](https://github.com/KevinnZou/compose-multiplatform-library-template/actions/workflows/build.yml)
[](https://github.com/KevinnZou/compose-multiplatform-library-template/actions/workflows/wiki.yml)
[](https://github.com/ismai117/KScan/releases/latest)
[](https://github.com/ismai117/KScan/releases)
KScan
Compose Multiplatform Barcode Scanning Library
![]()
![]()
![]()
![]()
KScan is a Compose Multiplatform library that makes it easy to scan barcodes in your apps
To integrate KScan into your project
Add the dependency in your common module's commonMain source set
```Kotlin
implementation("io.github.ismai117:KScan:0.1.0-alpha05")
```
Android - MLKit
- Uses Google’s MLKit library for barcode scanning on AndroidiOS - AVFoundation
- Utilizes Apple’s AVFoundation framework for camera setup and barcode scanning on iOS
Important: iOS requires you to add the "Privacy - Camera Usage Description" key to your Info.plist file inside xcode, you need to provide a reason for why you want to access the camera.Basic Usage
To use KScan, simply add the ScannerView in your app like this:
```Kotlin
if (showScanner) {
ScannerView(
codeTypes = listOf(
BarcodeFormats.FORMAT_QR_CODE,
BarcodeFormats.FORMAT_EAN_13,
)
) { result ->
when (result) {
is BarcodeResult.OnSuccess -> {
println("Barcode: ${result.barcode.data}, format: ${result.barcode.format}")
}
is BarcodeResult.OnFailed -> {
println("error: ${result.exception.message}")
}
BarcodeResult.OnCanceled -> {
println("scan canceled")
}
}
}
}
```To dismiss the scanner, you need to manage your own state, set it to false in the right places inside the ScannerView block after you handle the results
```Kotlin
if (showScanner) {
ScannerView(
codeTypes = listOf(
BarcodeFormats.FORMAT_QR_CODE,
BarcodeFormats.FORMAT_EAN_13,
)
) { result ->
when (result) {
is BarcodeResult.OnSuccess -> {
println("Barcode: ${result.barcode.data}, format: ${result.barcode.format}")
showScanner = false
}
is BarcodeResult.OnFailed -> {
println("Error: ${result.exception.message}")
showScanner = false
}
BarcodeResult.OnCanceled -> {
showScanner = false
}
}
}
}
```