Skip to content

Instantly share code, notes, and snippets.

@fvilarino
Created September 18, 2023 20:50
Show Gist options
  • Save fvilarino/47580d0f1da154421dd6570af98f3970 to your computer and use it in GitHub Desktop.
Save fvilarino/47580d0f1da154421dd6570af98f3970 to your computer and use it in GitHub Desktop.
MVI Framework - Updated Counter Screen
@Composable
fun CounterScreen(
state: CounterState,
onDecreaseClick: () -> Unit,
onIncreaseClick: () -> Unit,
onGenerateRandom: () -> Unit,
modifier: Modifier = Modifier,
) {
Box(
contentAlignment = Alignment.Center,
modifier = modifier,
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
) {
IconButton(
onClick = onDecreaseClick,
enabled = !state.loading,
) {
Icon(
imageVector = Icons.Default.RemoveCircleOutline,
contentDescription = "decrement"
)
}
Text(
text = state.counter.toString(),
style = MaterialTheme.typography.displaySmall,
modifier = Modifier.padding(horizontal = 16.dp),
)
IconButton(
onClick = onIncreaseClick,
enabled = !state.loading,
) {
Icon(
imageVector = Icons.Default.AddCircleOutline,
contentDescription = "increment"
)
}
}
Button(
onClick = onGenerateRandom,
enabled = !state.loading,
modifier = Modifier.padding(top = 16.dp),
) {
Text(
text = "Generate Random"
)
}
}
if (state.loading) {
CircularProgressIndicator()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment