@ -79,6 +79,7 @@ private fun CameraWithGrantedPermission(
val context = LocalContext . current
val context = LocalContext . current
val lifecycleOwner = LocalLifecycleOwner . current
val lifecycleOwner = LocalLifecycleOwner . current
val viewScope = rememberCoroutineScope ( )
val viewScope = rememberCoroutineScope ( )
var cameraProvider : ProcessCameraProvider ? by remember { mutableStateOf ( null ) }
val preview = Preview . Builder ( ) . build ( )
val preview = Preview . Builder ( ) . build ( )
val previewView = remember { PreviewView ( context ) }
val previewView = remember { PreviewView ( context ) }
@ -96,16 +97,22 @@ private fun CameraWithGrantedPermission(
. build ( )
. build ( )
}
}
DisposableEffect ( Unit ) {
onDispose {
cameraProvider ?. unbindAll ( )
}
}
LaunchedEffect ( isFrontCamera ) {
LaunchedEffect ( isFrontCamera ) {
val cameraProvider = suspendCoroutine < ProcessCameraProvider > { continuation ->
cameraProvider = suspendCoroutine < ProcessCameraProvider > { continuation ->
ProcessCameraProvider . getInstance ( context ) . also { cameraProvider ->
ProcessCameraProvider . getInstance ( context ) . also { cameraProvider ->
cameraProvider . addListener ( {
cameraProvider . addListener ( {
continuation . resume ( cameraProvider . get ( ) )
continuation . resume ( cameraProvider . get ( ) )
} , executor )
} , executor )
}
}
}
}
cameraProvider . unbindAll ( )
cameraProvider ? .unbindAll ( )
cameraProvider . bindToLifecycle (
cameraProvider ? .bindToLifecycle (
lifecycleOwner ,
lifecycleOwner ,
cameraSelector ,
cameraSelector ,
preview ,
preview ,