The problem with this code was that in the screen composable I create the viewModel with the class constructor, like so:
@Composable
fun CameraScreen(
modifier: Modifier = Modifier,
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
cameraViewModel: CameraViewModel = CameraViewModel(),
)
Which doesn't make it part of the composition, nor does it save its state. To solve this I just changed the assignment of the default value as follows:
@Composable
fun CameraScreen(
modifier: Modifier = Modifier,
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
cameraViewModel: CameraViewModel = viewModel()
)
And now everything works correctly!