I have a simple CountDown indicator which is made ...
# compose-desktop
g
I have a simple CountDown indicator which is made like so:
Copy code
@Composable
fun BreakPopup(
    duration: ZbTimeData,
    onTimeFinished: () -> Unit,
) {
    var progress by remember {
        mutableStateOf(1F)
    }
    val animatedProgress by animateFloatAsState(
        targetValue = progress,
        animationSpec = tween(
            durationMillis = duration.millis.toInt(),
            easing = LinearEasing
        ),
        finishedListener = {
            onTimeFinished()
        }
    )

    LaunchedEffect(Unit) {
        progress = 0F
    }

    // Etc...
    RoundedCornersCircularProgressIndicator(
        progress = animatedProgress,
        color = textColor,
        strokeWidth = 8.dp,
        modifier = Modifier
            .fillMaxSize()
            .padding(8.dp)
    )
And I show it in a simple window
Copy code
Window(
    visible = isPopupWindowVisible
) {
    BreakPopup(message = settings.value.breakMessage,
        duration = settings.value.breakDuration,
        onTimeFinished = {
            isPopupWindowVisible = false
        },
    )
}
I’m encountering a weird issue where the composable doesn’t seem to get disposed when the window is not visible anymore, because the first time it works correctly, while from the second time and on the progress is already at
0F
, and it seems like it’s holding the same composable with the old values instead of recreating it when the window is not visible anymore
a
You can pass the progress from outside, or wrap it in
key
(and change the key every time you show the window).
e.g.
key(showCounter){ BreakPopup(…) }
g
Yeah, but isn't that a bug in the library, or is it normal behaviour?
a
Perhaps one could expect either behavior. Not 100% sure.
g
Okay thank you 👍
i
It is by design that
visible
doesn't dispose the composition