Created
September 15, 2022 09:51
-
-
Save rajendhirandev/369ef9dc718ffda52606dd23a6a02903 to your computer and use it in GitHub Desktop.
Stateful Compose Sample
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 MyCounterStateful() { | |
var vStart by remember { mutableStateOf(5) } | |
var vEnd by remember { mutableStateOf(7) } | |
var noOfTimes by remember { mutableStateOf(0) } | |
ComposePracticesTheme { | |
Column(modifier = Modifier.padding(15.dp)) { | |
Text(text = "Welcome to the Counter") | |
Button(onClick = { | |
noOfTimes++ | |
}) { | |
val msg = if (noOfTimes == 0) | |
"Click Me" | |
else | |
"I've Clicked by $noOfTimes times" | |
Text(text = msg) | |
} | |
AnimatedVisibility(visible = noOfTimes in vStart..vEnd + 1) { | |
Text( | |
text = "I'm Visible between $vStart to $vEnd", | |
modifier = Modifier | |
) | |
if (noOfTimes == vEnd + 1) { | |
vStart = noOfTimes + 5 | |
vEnd = vStart + 2 | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment