I’ve a composable that contains a text composable which displays the a duration string provided in the params of the composable function.
The problem is that the duration string is getting updated with change in value smoothly when I’m installing a debug build but when I install a release build the duration string gets updated till “00:02” and gets stuck at “00:02”, after this it does not update anymore.
//this is how I'm calling it
CallStatusInfo(
modifier = Modifier
.align(Alignment.Center)
.padding(vertical = 8.dp),
callStatus = viewModel.callStatus,
callDuration = viewModel.callDuration
)
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun CallStatusInfo(modifier: Modifier = Modifier, callStatus: String, callDuration: String?) {
Text(
modifier = modifier.basicMarquee(),
text = when(callStatus){
"ringing" -> "ringing"
"connected" -> callDuration ?: ""
else -> ""
},
style = MaterialTheme.typography.body2,
fontWeight = FontWeight.W600,
maxLines = 1
)
}
In order to reproduce this one can create a viewModel by using Hilt and then use this:
Note: The code below is not my exact code but a short version of it.
var callDuration by mutableStateOf<String?>(null)
private set
var callStatus by mutableStateOf<String>("connected")
private set
private var startTime = Instant.now()
init {
viewModelScope.launch {
while (true) {
val timeElapsed = System.currentTimeMillis() - startTime.toEpochMilli()
val duration = formatTimeToDuration(timeElapsed)
callDuration = duration
delay(1.seconds)
}
}
}
I tried logging inside the composable and found that the parameter value is getting changed every second but the composable is still not updating in release build.
One more strange thing is as soon as I touch or interact with any other component on the screen, the duration starts getting updated.
Would love some help here as I’ve been stuck with this strange issue for a long time with no results.