Giuliopime
07/13/2023, 1:01 PM@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
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 anymoreAlexander Maryanovsky
07/13/2023, 2:34 PMkey
(and change the key every time you show the window).Alexander Maryanovsky
07/13/2023, 2:36 PMkey(showCounter){ BreakPopup(…) }
Giuliopime
07/13/2023, 3:02 PMAlexander Maryanovsky
07/13/2023, 3:05 PMGiuliopime
07/13/2023, 3:11 PMIgor Demin
07/14/2023, 8:01 AMvisible
doesn't dispose the composition