Created
December 5, 2021 13:36
-
-
Save enyciaa/2b6fe0536e8f66a2d7fb712d3cfdb3c5 to your computer and use it in GitHub Desktop.
screen-template-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyFabScreenViewModel( | |
private val navigator: Navigator, | |
) : MotherViewModel<MyFabScreenViewModel.ViewState, MyFabScreenViewModel.UiAction>() { | |
override fun onAttach() { | |
super.onAttach() | |
flowOf(ScreenState.Loaded) | |
.onEach { delay(5000) } | |
.flowOn(Dispatchers.Default) | |
.onEach { emit(lastViewState.copy(screenState = it)) } | |
.launchIn(coroutineScope) | |
} | |
override fun onAction(action: UiAction) { | |
when (action) { | |
UiAction.NextClicked -> navigator.goToSecondScreen() | |
} | |
} | |
override fun defaultViewState(): ViewState { | |
return ViewState( | |
screenToolbarViewState = ScreenToolbarViewState("My First Screen"), | |
screenCallToActionViewState = ScreenCallToActionViewState("Next"), | |
screenState = ScreenState.Loading, | |
) | |
} | |
data class ViewState( | |
val screenToolbarViewState: ScreenToolbarViewState, | |
val screenCallToActionViewState: ScreenCallToActionViewState, | |
val screenState: ScreenState, | |
) : MotherViewModel.ViewState | |
sealed class UiAction : MotherViewModel.UiAction { | |
object NextClicked : UiAction() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment