Created
August 7, 2022 13:32
-
-
Save motorro/767efebcd7d946fdf50112f108d1053c to your computer and use it in GitHub Desktop.
ViewModel with a state-factory
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
@HiltViewModel | |
class LoginViewModel @Inject constructor(private val factory: LoginStateFactory) : ViewModel() { | |
/** | |
* Creates initializing state | |
*/ | |
private fun initializeStateMachine(): CommonMachineState<WelcomeGesture, WelcomeUiState> { | |
// Obtain data required to start from a saved-state handle or injection | |
val commonData = LoginDataState() | |
return factory.passwordEntry(commonData) | |
} | |
/** | |
* State machine | |
*/ | |
private val stateMachine = FlowStateMachine(::initializeStateMachine) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment