Last active
October 17, 2021 15:51
-
-
Save sproctor/25f7db41252cf0ce450d2bf958a5427a to your computer and use it in GitHub Desktop.
launched effect example
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 TimeDisplay(viewModel: TimeDisplayViewModel) { | |
val properties: Map<String, Long> by viewModel.properties.collectAsState() | |
var timeRemaining by rememeber { mutableStateOf(0) } | |
Text(timeRemaining.toString) | |
val timeProperty = properties["time"] | |
LaunchedEffect(timeProperty) { | |
val currentTime = System.currentTimeMillis() | |
while (timeProperty > currentTime) { | |
timeRemaining = timeProperty - currentTime | |
delay(1000L) | |
} | |
timeRemaining = 0L | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment