Created
September 18, 2023 20:50
-
-
Save fvilarino/47580d0f1da154421dd6570af98f3970 to your computer and use it in GitHub Desktop.
MVI Framework - Updated Counter Screen
This file contains hidden or 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 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