Move usage of LocalInspectionMode.current into the deeper block.

This commit is contained in:
Benoit Marty 2025-12-11 17:33:24 +01:00
parent 6100d4944f
commit 06c20e3abf

View file

@ -48,15 +48,6 @@ fun QrCodeCameraView(
isScanning: Boolean,
modifier: Modifier = Modifier,
) {
if (LocalInspectionMode.current) {
Box(
modifier = modifier
.background(color = ElementTheme.colors.bgSubtlePrimary),
contentAlignment = Alignment.Center,
) {
Text("CameraView")
}
} else {
val coroutineScope = rememberCoroutineScope()
val localContext = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current
@ -90,7 +81,7 @@ fun QrCodeCameraView(
lifecycleOwner,
cameraSelector,
previewUseCase,
imageAnalysis
imageAnalysis,
)
lastFrame = null
} catch (e: Exception) {
@ -120,6 +111,15 @@ fun QrCodeCameraView(
}
Box(modifier.clipToBounds()) {
if (LocalInspectionMode.current) {
Box(
modifier = modifier
.background(color = ElementTheme.colors.bgSubtlePrimary),
contentAlignment = Alignment.Center,
) {
Text("CameraView")
}
} else {
AndroidView(
factory = { context ->
val previewView = PreviewView(context)
@ -145,11 +145,11 @@ fun QrCodeCameraView(
cameraProvider = null
},
)
}
lastFrame?.let {
Image(bitmap = it.asImageBitmap(), contentDescription = null)
}
}
}
}
private suspend fun Context.getCameraProvider(): ProcessCameraProvider =
@ -159,7 +159,7 @@ private suspend fun Context.getCameraProvider(): ProcessCameraProvider =
{
continuation.resume(cameraProvider.get())
},
ContextCompat.getMainExecutor(this)
ContextCompat.getMainExecutor(this),
)
}
}