I have a property called captureMode which observe...
# codereview
n
I have a property called captureMode which observes on a camera
StateFlow
and change it’s value when the camera changes. Additionally, I want to be able to set captureMode manually. But since captureMode is a stateFlow, I can’t set it. Is there a better way?
e
How about:
Copy code
val mutableCaptureMode = MutableStateFlow<CaptureMode?>(null)

private val captureMode = camera.combine(mutableCaptureMode) { item, mutableMode ->
     if (mutableMode != null) emit(mutableMode)
     else if (item.foo) {
         emit(CaptureMode.Panoramic)
     } else {
         emit(CaptureMode.Standard)
     }
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), CaptureMode.Panoramic)

fun setCaptureMode(mode: CaptureMode) { mutableCaptureMode.value = mode }
n
genius! 🧠
thanks!