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