Skip to content

Instantly share code, notes, and snippets.

View shoaibmushtaq25's full-sized avatar

Shoaib Mushtaq shoaibmushtaq25

View GitHub Profile
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.progressSemantics
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
val animateFloat = remember { Animatable(0f) }
LaunchedEffect(animateFloat) {
animateFloat.animateTo(
targetValue = currentValue / maxValue.toFloat(),
animationSpec = tween(durationMillis = 2000, easing = FastOutSlowInEasing)
)
}
Canvas(
Modifier
.progressSemantics(currentValue / maxValue.toFloat())
.size(CircularIndicatorDiameter)
) {
// Start at 12 O'clock
val startAngle = 270f
val sweep: Float = animateFloat.value * 360f
val diameterOffset = stroke.width / 2
private fun DrawScope.drawCircularProgressIndicator(
startAngle: Float,
sweep: Float,
color: Color,
stroke: Stroke
) {
// To draw this circle we need a rect with edges that line up with the midpoint of the stroke.
// To do this we need to remove half the stroke width from the total diameter for both sides.
val diameterOffset = stroke.width / 2
val arcDimen = size.width - 2 * diameterOffset
@Composable
private fun ProgressStatus(
currentValue: Int,
maxValue: Int,
progressBackgroundColor: Color,
progressIndicatorColor: Color,
completedColor: Color, modifier: Modifier = Modifier
) {
Text(modifier = modifier, text = buildAnnotatedString {
val emphasisSpan =
AnimatedCircularProgressIndicator(
currentValue = 17,
maxValue = 20,
progressBackgroundColor = Purple80,
progressIndicatorColor = PurpleGrey40,
completedColor = Purple40
)