Compose Multiplatform Views
The scandit-kmp-datacapture-barcode-compose module exposes the barcode capture modes as
@Composable functions. Each bundles the mode, its view and overlay into a single
declarative entry point: a remember* helper builds the mode, and a *View composable
renders it. See Using the SDK with Compose Multiplatform for the shared setup.
Dependency
Add the barcode Compose companion to your commonMain source set (it pulls in the base
barcode module transitively); it builds on core-compose:
commonMain.dependencies {
implementation("com.scandit.datacapture.kmp:core-compose:<version>")
implementation("com.scandit.datacapture.kmp:barcode-compose:<version>")
}
SparkScan
@Composable
fun SparkScanScreen() {
SparkScanView(
settings = SparkScanSettings.sparkScanSettings(),
modifier = Modifier.fillMaxSize(),
onScan = { barcodes -> /* handle scanned barcodes */ },
)
}
Barcode Count
BarcodeCountView(
settings = BarcodeCountSettings.barcodeCountSettings(),
modifier = Modifier.fillMaxSize(),
onScan = { barcodes -> /* handle counted barcodes */ },
)
Barcode Find
BarcodeFindView(
settings = BarcodeFindSettings.barcodeFindSettings(),
itemsToFind = itemsToFind, // your Set<BarcodeFindItem>
modifier = Modifier.fillMaxSize(),
onFinishTap = { found -> /* handle the found items */ },
)
Views with an explicit lifecycle
Barcode AR and Barcode Pick expose an imperative lifecycle (start, pause, stop, reset / freeze)
that does not fit the pure data-driven model. For those the composable takes a state holder you
create with a remember* helper and drive from your composition or your host’s lifecycle:
BarcodeArViewStatefor theBarcodeArViewcomposable.BarcodePickViewStatefor theBarcodePickViewcomposable.
@Composable
fun PickScreen() {
val state = rememberBarcodePickViewState()
BarcodePickView(
settings = pickSettings, // your BarcodePickSettings
productProvider = productProvider, // your BarcodePickAsyncMapperProductProvider
state = state,
modifier = Modifier.fillMaxSize(),
)
LaunchedEffect(Unit) { state.start() }
}
BarcodeArView follows the same shape with rememberBarcodeArViewState().
stop() is a terminal teardown: the view is no longer usable afterwards. For a temporary
pause that can be resumed with start(), use pause() (and freeze() on
BarcodePickViewState).