Advertisement
Kostiggig

Untitled

Sep 5th, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. var progress by remember {
  2. mutableFloatStateOf(0f)
  3. }
  4. val color: Color by animateColorAsState(
  5. when (progress) {
  6. in (0.0..0.25) -> Color.Red
  7. in (0.26f..0.5f) -> Color.Green
  8. in (0.51f..0.75f) -> Color.Blue
  9. else -> Color.Black
  10. }, label = ""
  11. )
  12. val scope = rememberCoroutineScope()
  13. LaunchedEffect(Unit) {
  14. scope.launch {
  15. while(progress < 1f) {
  16. delay(1000)
  17. progress += 0.25f
  18. }
  19. }
  20. }
  21. Progress(
  22. modifier = Modifier.padding(horizontal = 20.dp),
  23. color = color,
  24. progress = progress
  25. )
  26.  
  27. @Composable
  28. fun Progress(
  29. progress: Float,
  30. color: Color,
  31. modifier: Modifier = Modifier
  32. ) {
  33. require(progress in (0.0..1.0)) {
  34. "progress must be in range [0.0, 1.0]"
  35. }
  36. Column(
  37. modifier = modifier
  38. ) {
  39. Image(
  40. modifier = Modifier
  41. .height(8.dp)
  42. .fillMaxWidth(),
  43. painter = painterResource(id = R.drawable.shadow),
  44. contentScale = ContentScale.FillBounds,
  45. contentDescription = null
  46. )
  47. Box(
  48. modifier = Modifier
  49. .height(8.dp)
  50. .fillMaxWidth(fraction = progress)
  51. .clip(RoundedCornerShape(16.dp))
  52. .background(color)
  53. )
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement