Gradient Animated

This commit is contained in:
shabinder 2021-09-25 22:28:32 +05:30
parent 7725bc8602
commit 758fe62254

View File

@ -19,6 +19,7 @@ package com.shabinder.common.uikit.utils
import android.util.Log import android.util.Log
import androidx.compose.animation.core.TweenSpec import androidx.compose.animation.core.TweenSpec
import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
@ -68,11 +69,17 @@ fun Modifier.verticalGradientScrim(
} }
} }
var height by remember { mutableStateOf(fixedHeight ?: 1f) } var height by remember { mutableStateOf(fixedHeight ?: 1f) }
val brush = remember(color, numStops, startYPercentage, endYPercentage, height) { val scrimHeight by animateFloatAsState(
// Whenever the target value changes, new animation
// will start to the new target value
targetValue = height,
animationSpec = tween(durationMillis = 1500)
)
val brush = remember(color, numStops, startYPercentage, endYPercentage, scrimHeight) {
Brush.verticalGradient( Brush.verticalGradient(
colors = colors, colors = colors,
startY = height * startYPercentage, startY = scrimHeight * startYPercentage,
endY = height * endYPercentage endY = scrimHeight * endYPercentage
) )
} }