Module name | Gestures | UI-states |
---|---|---|
welcome | WelcomeGesture | WelcomeUiState |
login | LoginGesture | LoginUiState |
commonregister | RegisterGesture | RegisterUiState |
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
@Composable | |
fun LoginScreen(state: LoginUiState, onGesture: (LoginGesture) -> Unit) { | |
// Login screen rendering... | |
} | |
@Composable | |
fun RegistrationScreen(state: RegisterUiState, onGesture: (RegisterGesture) -> Unit) { | |
// Registration screen rendering... | |
} |
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
sealed class WelcomeUiState { | |
/** | |
* Login state wrapper | |
* @property value Login UI state | |
*/ | |
data class Login(val value: LoginUiState) : WelcomeUiState() | |
/** | |
* Register state wrapper | |
* @property value Register UI state |
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
sealed class WelcomeGesture { | |
// Native gestures... | |
/** | |
* Login flow gesture | |
* @property value Login flow gesture | |
*/ | |
data class Login(val value: LoginGesture) : WelcomeGesture() | |
/** |
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
interface LoginContext { | |
/** | |
* Flow host | |
*/ | |
val host: WelcomeFeatureHost | |
// Other dependencies... | |
} |
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 WithIdleViewModel : ViewModel() { | |
/** | |
* Creates initial state for state-machine | |
* You could process a deep-link here or restore from a saved state | |
*/ | |
private fun initStateMachine(): CommonMachineState<SomeGesture, SomeUiState> = InitialState() | |
/** | |
* State-machine instance | |
*/ |
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
open class FlowStateMachine<G: Any, U: Any>( | |
init: () -> CommonMachineState<G, U> | |
) : CommonStateMachine.Base<G, U>(init) { | |
private val mediator = MutableSharedFlow<U>( | |
replay = 1, | |
onBufferOverflow = BufferOverflow.DROP_OLDEST | |
) | |
init { |
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 CredentialsCheckState( | |
data: LoginDataState, | |
private val checkCredentials: CheckCredentials | |
) : CoroutineState<LoginGesture, LoginUiState>() { | |
// State logic | |
/** | |
* Dedicated 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) |
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 CredentialsCheckStateTest { | |
private val data = LoginDataState() | |
private val factory: LoginStateFactory = mockk() | |
private val passwordEntry: LoginState = mockk() | |
@Test | |
fun returnsToPasswordEntryOnBack() = runTest { | |
every { factory.passwordEntry(any()) } returns passwordEntry | |
state.start(stateMachine) |