Chaintech-Network / QRKitComposeMultiplatform

112 stars 6 forks source link

The IOS camera freezes, on Android it works fine #2

Closed MiguelAngelBadi closed 1 week ago

MiguelAngelBadi commented 1 month ago

Hello, I have modified the code to scan QR codes one after the other without having to click on Scan QR. On Android it works perfectly for me but on IOS the camera freezes. Could you help me?

The code is the following:

fun QrScannerCompose() {

var qrCodeURL by remember { mutableStateOf("") }
var startBarCodeScan by remember { mutableStateOf(false) }
var flashlightOn by remember { mutableStateOf(false) }
var launchGallery by remember { mutableStateOf(value = false) }
val snackBarHostState = LocalSnackBarHostState.current
val coroutineScope = rememberCoroutineScope()

Box(modifier = Modifier.fillMaxSize().statusBarsPadding()) {
    Column(
        modifier = Modifier
            .background(color = Color.White)
            .windowInsetsPadding(WindowInsets.safeDrawing)
            .fillMaxSize(),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
            Column(
                modifier = Modifier
                    .background(color = Color.Black)
                    .fillMaxSize(),
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Box(
                    modifier = Modifier
                        .size(250.dp)
                        .clip(shape = RoundedCornerShape(size = 14.dp))
                        .clipToBounds()
                        .border(2.dp, Color.Gray, RoundedCornerShape(size = 14.dp)),
                    contentAlignment = Alignment.Center
                ) {
                    QrScanner(
                        modifier = Modifier
                            .clipToBounds()
                            .clip(shape = RoundedCornerShape(size = 14.dp)),
                        flashlightOn = flashlightOn,
                        launchGallery = launchGallery,
                        onCompletion = {
                            qrCodeURL = it
                            startBarCodeScan = false
                        },
                        onGalleryCallBackHandler = {
                            launchGallery = it
                        },
                        onFailure = {
                            coroutineScope.launch {
                                if (it.isEmpty()) {
                                    snackBarHostState.showSnackbar("Invalid qr code")
                                } else {
                                    snackBarHostState.showSnackbar(it)
                                }
                            }
                        }
                    )
                }

                Box(
                    modifier = Modifier
                        .padding(start = 20.dp, end = 20.dp, top = 30.dp)
                        .background(
                            color = Color(0xFFF9F9F9),
                            shape = RoundedCornerShape(25.dp)
                        )
                        .height(35.dp),
                    contentAlignment = Alignment.Center
                ) {
                    Row(
                        modifier = Modifier
                            .padding(vertical = 5.dp, horizontal = 18.dp),
                        verticalAlignment = Alignment.CenterVertically,
                        horizontalArrangement = Arrangement.spacedBy(11.dp)
                    ) {
                        Icon(imageVector = if (flashlightOn) Icons.Filled.FlashOn else Icons.Filled.FlashOff,
                            "flash",
                            modifier = Modifier
                                .size(24.dp)
                                .clickable {
                                    flashlightOn = !flashlightOn
                                })

                        VerticalDivider(
                            modifier = Modifier,
                            thickness = 1.dp,
                            color = Color(0xFFD8D8D8)
                        )

                        Image(
                            painter = painterResource(Res.drawable.ic_gallery_icon),
                            contentDescription = "gallery",
                            contentScale = ContentScale.Fit,
                            modifier = Modifier
                                .size(24.dp)
                                .clickable {
                                    launchGallery = true
                                }
                        )
                    }
                }
                Spacer(modifier = Modifier.height(8.dp))

                Box(
                    modifier = Modifier
                        .padding(bottom = 8.dp)
                ) {
                    Text(
                        text = "El código es: $qrCodeURL",
                        color = Color.White,
                        fontSize = 16.sp,
                        modifier = Modifier.padding(bottom = 16.dp)
                    )
                }
            }
    }
}

}

I attach the video where you can see that on Android it works perfectly, and on IOS it freezes after scanning the first QR code.

https://github.com/ChainTechNetwork/QRKitComposeMultiplatform/assets/34895469/3a775bb2-ae70-471e-b726-8a69d091b237

ctn-mobile-innovation commented 1 month ago

Thanks For reporting! Let us check and get back to you

jishinhv commented 2 weeks ago

@ctn-mobile-innovation any updates? Do we have any temporary fixes for the time being?

ctn-mobile-innovation commented 2 weeks ago

We had worked on fix and will publish this this week!

ctn-mobile-innovation commented 1 week ago

@MiguelAngelBadi @jishinhv Please check in new version and let us know!

ctn-mobile-innovation commented 1 week ago

Fixed in v 1.0.8

MiguelAngelBadi commented 6 days ago

@MiguelAngelBadi @jishinhv Please check in new version and let us know!

It works perfectly, thank you very much :)