yuriy-budiyev / code-scanner

Code scanner library for Android, based on ZXing
MIT License
1.09k stars 266 forks source link

Camera too dark when embed CodeScannerView to Jetpack Compose #173

Open rizmaulana opened 1 year ago

rizmaulana commented 1 year ago

Hi @yuriy-budiyev i start use this library to scan many kind of qr and barcode, but when it come to Jetpack Compose, I have a trouble : the camera is too dark.

I try to build from https://github.com/yuriy-budiyev/lib-demo-app everything looks good, so I assume is the problem is not related to the android device

From demo app From Jetpack Compose App
2022-12-22 15 12 09 2022-12-22 15 12 19

Here is my code :

@Composable
private fun CameraView(
    qrCodeReturn: (String) -> Unit
) {
    Box(Modifier.fillMaxSize()) {
        AndroidView(
            modifier = Modifier,
            factory = {
                CodeScannerView(it).apply {
                    val codeScanner = CodeScanner(it, this).apply {
                        isAutoFocusEnabled = true
                        isAutoFocusButtonVisible = false
                        scanMode = ScanMode.SINGLE
                        decodeCallback = DecodeCallback { result ->
                            qrCodeReturn.invoke(result.text)
                            releaseResources()
                        }
                        errorCallback = ErrorCallback {
                            releaseResources()
                        }
                    }
                    codeScanner.startPreview()
                }
            },
        )
    }
}

TIA