Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var progress by remember {
- mutableFloatStateOf(0f)
- }
- val color: Color by animateColorAsState(
- when (progress) {
- in (0.0..0.25) -> Color.Red
- in (0.26f..0.5f) -> Color.Green
- in (0.51f..0.75f) -> Color.Blue
- else -> Color.Black
- }, label = ""
- )
- val scope = rememberCoroutineScope()
- LaunchedEffect(Unit) {
- scope.launch {
- while(progress < 1f) {
- delay(1000)
- progress += 0.25f
- }
- }
- }
- Progress(
- modifier = Modifier.padding(horizontal = 20.dp),
- color = color,
- progress = progress
- )
- @Composable
- fun Progress(
- progress: Float,
- color: Color,
- modifier: Modifier = Modifier
- ) {
- require(progress in (0.0..1.0)) {
- "progress must be in range [0.0, 1.0]"
- }
- Column(
- modifier = modifier
- ) {
- Image(
- modifier = Modifier
- .height(8.dp)
- .fillMaxWidth(),
- painter = painterResource(id = R.drawable.shadow),
- contentScale = ContentScale.FillBounds,
- contentDescription = null
- )
- Box(
- modifier = Modifier
- .height(8.dp)
- .fillMaxWidth(fraction = progress)
- .clip(RoundedCornerShape(16.dp))
- .background(color)
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement