-
-
Save droid-it/15ddcbe8b62b5fdbc40da9af48533ab4 to your computer and use it in GitHub Desktop.
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 TimerScreen1() { | |
Column( | |
modifier = Modifier | |
.fillMaxSize(), | |
horizontalAlignment = Alignment.CenterHorizontally | |
) { | |
var timerDuration by remember { | |
mutableStateOf(1000L) // default value = 1 sec | |
} | |
Button({ | |
timerDuration -= 1000 | |
}) { | |
Text("-1 second") | |
} | |
Text(timerDuration.toString()) | |
Button({ | |
timerDuration += 1000 | |
}) { | |
Text("+1 second") | |
} | |
Timer(timerDuration = timerDuration) | |
} | |
} | |
@Composable | |
fun Timer(timerDuration: Long) { | |
LaunchedEffect(key1 = timerDuration, block = { | |
try { | |
startTimer(timerDuration) { | |
println("Timer ended") | |
} | |
} catch (ex: Exception) { | |
println("timer cancelled") | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment