adeo-opensource / kviewmodel--mpp

Library to sharing view model
Apache License 2.0
48 stars 4 forks source link

Action does not work correctly #24

Open Ly41k opened 7 months ago

Ly41k commented 7 months ago

Problem: When I try to go back to the previous screen - I get the previous Action again

Solution: I think the error is in this line: private val _viewActions = MutableSharedFlow<Action?>(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST) - we specified replay = 1, for one-time events it is better to use MutableSharedFlow<Action?>(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)

Then everything works correctly

https://github.com/adeo-opensource/kviewmodel--mpp/assets/59660150/3bceedc1-a56b-43f1-8df0-22d904b5201e

ilhomsoliev commented 3 months ago

I have the same issue but the solution you proposed is not working

ilhomsoliev commented 3 months ago

I do it this way for it to work:

LaunchedEffect(viewAction.value) { viewAction.value?.let { when (it) { LoginAction.OpenHome -> openCodeScreen(viewState.phone) LoginAction.GoBack -> { "Comes here action".printToLog() onBack() } } } }