Skip to content

ProgressIndicator

ProgressIndicator is a progress indication component in Miuix used to display the progress status of operations. It provides three styles: linear progress bar, circular progress indicator, and infinite spinning indicator, suitable for different loading and progress display scenarios.

Import

kotlin
import top.yukonga.miuix.kmp.basic.LinearProgressIndicator // Linear progress bar
import top.yukonga.miuix.kmp.basic.CircularProgressIndicator // Circular progress indicator
import top.yukonga.miuix.kmp.basic.InfiniteProgressIndicator // Infinite spinning indicator

Basic Usage

Linear Progress Bar

Linear progress bar can be used to show operation progress:

kotlin
// Linear progress bar with determinate progress
var progress by remember { mutableStateOf(0.3f) }

LinearProgressIndicator(progress = progress)
kotlin
// Linear progress bar with indeterminate progress
LinearProgressIndicator()

Circular Progress Indicator

Circular progress indicator is suitable for space-saving scenarios:

kotlin
// Circular progress indicator with determinate progress
var progress by remember { mutableStateOf(0.7f) }

CircularProgressIndicator(progress = progress)
kotlin
// Circular progress indicator with indeterminate progress
CircularProgressIndicator()

Infinite Progress Indicator

Infinite progress indicator is suitable for scenarios where operation duration is uncertain:

kotlin
InfiniteProgressIndicator()

Component States

All progress indicator components support both determinate and indeterminate progress states:

Determinate Progress State

When a specific progress value (float between 0.0-1.0) is provided, the progress indicator shows exact progress:

kotlin
var progress by remember { mutableStateOf(0.6f) }

LinearProgressIndicator(progress = progress)
CircularProgressIndicator(progress = progress)

Indeterminate Progress State

When the progress value is null, the progress indicator shows an animation indicating an ongoing operation with unknown progress:

kotlin
LinearProgressIndicator(progress = null)
CircularProgressIndicator(progress = null)

Properties

LinearProgressIndicator Properties

Property NameTypeDescriptionDefault ValueRequired
progressFloat?Current progress value, null for indeterminatenullNo
modifierModifierModifier applied to the progress barModifierNo
colorsProgressIndicatorColorsColor configuration for the progress barProgressIndicatorDefaults.progressIndicatorColors()No
heightDpHeight of the progress barProgressIndicatorDefaults.DefaultLinearProgressIndicatorHeightNo

CircularProgressIndicator Properties

Property NameTypeDescriptionDefault ValueRequired
progressFloat?Current progress value, null for indeterminatenullNo
modifierModifierModifier applied to the progress indicatorModifierNo
colorsProgressIndicatorColorsColor configuration for the progress indicatorProgressIndicatorDefaults.progressIndicatorColors()No
strokeWidthDpStroke width of the circular trackProgressIndicatorDefaults.DefaultCircularProgressIndicatorStrokeWidthNo
sizeDpSize of the circular indicatorProgressIndicatorDefaults.DefaultCircularProgressIndicatorSizeNo

InfiniteProgressIndicator Properties

Property NameTypeDescriptionDefault ValueRequired
modifierModifierModifier applied to the indicatorModifierNo
colorColorColor of the progress indicatorColor.GrayNo
sizeDpSize of the indicatorProgressIndicatorDefaults.DefaultInfiniteProgressIndicatorSizeNo
strokeWidthDpStroke width of the circular trackProgressIndicatorDefaults.DefaultInfiniteProgressIndicatorStrokeWidthNo
orbitingDotSizeDpSize of the orbiting dotProgressIndicatorDefaults.DefaultInfiniteProgressIndicatorOrbitingDotSizeNo

ProgressIndicatorDefaults Object

The ProgressIndicatorDefaults object provides default values and color configurations for progress indicator components.

Constants

Constant NameTypeDefault ValueDescription
DefaultLinearProgressIndicatorHeightDp6.dpDefault height of linear progress bar
DefaultCircularProgressIndicatorStrokeWidthDp4.dpDefault stroke width of circular indicator
DefaultCircularProgressIndicatorSizeDp30.dpDefault size of circular indicator
DefaultInfiniteProgressIndicatorStrokeWidthDp2.dpDefault stroke width of infinite indicator
DefaultInfiniteProgressIndicatorOrbitingDotSizeDp2.dpDefault orbiting dot size of infinite indicator
DefaultInfiniteProgressIndicatorSizeDp20.dpDefault size of infinite indicator

Methods

Method NameTypeDescription
progressIndicatorColors()ProgressIndicatorColorsCreates default color configuration for indicators

ProgressIndicatorColors Class

Property NameTypeDescription
foregroundColorColorForeground color of the progress indicator
disabledForegroundColorColorForeground color when indicator is disabled
backgroundColorColorBackground color of the progress indicator

Advanced Usage

Custom Colored Linear Progress Bar

kotlin
var progress by remember { mutableStateOf(0.4f) }

LinearProgressIndicator(
    progress = progress,
    colors = ProgressIndicatorDefaults.progressIndicatorColors(
        foregroundColor = Color.Red,
        backgroundColor = Color.LightGray
    )
)

Resized Circular Progress Indicator

kotlin
var progress by remember { mutableStateOf(0.75f) }

CircularProgressIndicator(
    progress = progress,
    size = 50.dp,
    strokeWidth = 6.dp
)

Loading State with Button

kotlin
var isLoading by remember { mutableStateOf(false) }
val scope = rememberCoroutineScope()

Button(
    onClick = {
        isLoading = true
        // Simulate operation
        scope.launch {
            delay(2000)
            isLoading = false
        }
    },
    enabled = !isLoading
) {
     AnimatedVisibility(
        visible = isLoading
    ) {
        CircularProgressIndicator(
            modifier = Modifier
                .padding(end = 8.dp),
            size = 20.dp,
            strokeWidth = 4.dp
        )
    }
    Text("Submit")
}

Custom Infinite Progress Indicator

kotlin
InfiniteProgressIndicator(
    color = MiuixTheme.colorScheme.primary,
    size = 40.dp,
    strokeWidth = 3.dp,
    orbitingDotSize = 4.dp
)

Loading State with Card

kotlin
var isLoading by remember { mutableStateOf(true) }

Card(
    modifier = Modifier
        .fillMaxWidth()
        .height(200.dp)
        .padding(16.dp)
) {
    Box(
        modifier = Modifier.fillMaxSize(),
        contentAlignment = Alignment.Center
    ) {
        if (isLoading) {
            Column(
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                CircularProgressIndicator()
                Spacer(modifier = Modifier.height(16.dp))
                Text("Loading...")
            }
        } else {
            Text("Content Loaded")
        }
    }
}
// Control loading state
LaunchedEffect(Unit) {
    delay(3000)
    isLoading = false
}

Released under the Apache-2.0 License