Skip to content

ismai117/KScan

Repository files navigation

KScan

License Latest release

A Compose Multiplatform barcode scanning library for Android and iOS.

Android iOS

Installation

Add the dependency to your commonMain source set:

implementation("io.github.ismai117:KScan:0.6.0")

Platform Setup

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>

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.

About

Compose Multiplatform Barcode Scanning

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 9

Languages