Skip to content

Instantly share code, notes, and snippets.

@Skyyo
Last active August 29, 2022 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skyyo/4d7995df2961113fbe0838a2e7223853 to your computer and use it in GitHub Desktop.
Save Skyyo/4d7995df2961113fbe0838a2e7223853 to your computer and use it in GitHub Desktop.
@Composable
fun InputValidationScreen(viewModel: InputValidationAutoViewModel = hiltViewModel()) {
val events = remember(viewModel.events, lifecycleOwner) {..}
val name by viewModel.name.collectAsStateWithLifecycle()
val creditCardNumber by viewModel.creditCardNumber.collectAsStateWithLifecycle()
val areInputsValid by viewModel.areInputsValid.collectAsStateWithLifecycle()
LaunchedEffect(Unit) {
events.collect { event ->
when (event) {
is ScreenEvent.ShowToast -> context.toast(event.messageId)
}
}
}
Column {
CustomTextField(
inputWrapper = name,
onValueChange = viewModel::onNameEntered
)
CustomTextField(
inputWrapper = creditCardNumber,
onValueChange = viewModel::onCardNumberEntered,
onImeKeyAction = viewModel::onContinueClick
)
Button(onClick = viewModel::onContinueClick, enabled = areInputsValid) {
Text(text = "Continue")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment