Skip to content

Instantly share code, notes, and snippets.

@motorro
Created August 7, 2022 13:32
Show Gist options
  • Save motorro/767efebcd7d946fdf50112f108d1053c to your computer and use it in GitHub Desktop.
Save motorro/767efebcd7d946fdf50112f108d1053c to your computer and use it in GitHub Desktop.
ViewModel with a state-factory
@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