0

I need to implement view to show the remaining time. I implemented the component itself and drew it on canvas, my custom component takes the following parameters: currentTime, minTime, maxTime.

@Composable
fun CustomProgressBar(
    currentTime: Float,
    minTime: Float,
    maxTime: Float,
    text: String
)

The essence of the view is that, starting from maxTime, it starts the countdown, that is, I need to show it animatedly. In the domain layer, I implemented a countdown timer with Kotlin flow.

If my custom view was not on the compose, then when the timer ticks, I would change the currentTime and call in my custom view postInvalidate(). Thus, I would have called the onDraw() method, which would redraw the view.

However, how can this be implemented in compose? I'm interested in the approach itself. I understand that I need to remember the currentTime and call my composable function every time with the new time. But as I said above, in addition to the current time, composable also accepts minTime, maxTime.

Is there some way to change only the current time (to perform a recomposition), but at the same time, so that the timer implementation does not go into composable, but remains in my domain layer. And at the same time, so that I do not have to constantly call my composable function with the entire set of parameters and change only the current time.

Please, help me.

testivanivan
  • 967
  • 13
  • 36

0 Answers0