Last active
November 29, 2023 06:02
-
-
Save ghasemdev/8bf6d5d5babc9b4e5d42ef5e5f1f1f16 to your computer and use it in GitHub Desktop.
MVI
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 interface LoginAction { | |
data object NavigateToTerm: LoginAction | |
data object Login: LoginAction | |
data object ShowDialog: LoginAction | |
data object HideDialog: LoginAction | |
} |
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 interface LoginEffect { | |
data object NavigateToHome: LoginEffect | |
data object ShowSnackBar: LoginEffect | |
data object ShowBottomSheet: LoginEffect | |
} |
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(navController: NavController) { | |
RegisterScreen( | |
navController = navController, | |
viewModel = hiltViewModel() | |
) | |
} | |
@Composable | |
private fun LoginScreen(navController: NavController, viewModel: LoginViewModel) { | |
val viewState by viewModel.state.collectAsStateWithlifeCycle() | |
LaunchEffect(Unit) { | |
viewModel.effect.collectLatest{ | |
// Handle Effect like navigation or snackbar | |
} | |
} | |
RegisterScreen( | |
viewState = navController, | |
onAction = { | |
when(it) { | |
is NavigateToTerms -> { | |
// Navigate | |
} | |
else -> viewModel.onAction(it) | |
} | |
} | |
) | |
} | |
@Composable | |
private fun LoginScreen(viewState: LoginViewState, onAction: (LoginAction) -> Unit)) { | |
// UI | |
} |
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 LoginViewModel: ViewModel() { | |
val state: // stateFlow | |
val effect: // chanell | |
fun onAction(action: LoginAction) { | |
when (action) { | |
// | |
} | |
} | |
private fun // | |
} |
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
data class LoginViewState ( | |
val isLoading: Boolean, | |
val username: String, | |
val password: String | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment