Skip to content

LoadingButton

A text button with a built-in loading state, mirroring ColorOS's COUILoadingButton: while loading the label is hidden, three tiny dots pulse in a staggered wave, and clicks are swallowed so the action cannot be triggered again.

Import

kotlin
import io.github.suqi8.coui.kmp.basic.LoadingButton
import io.github.suqi8.coui.kmp.basic.LoadingButtonDefaults

Basic Usage

kotlin
var isLoading by remember { mutableStateOf(false) }

LoadingButton(
    text = "Download",
    onClick = { isLoading = true },
    isLoading = isLoading,
    colors = ButtonDefaults.textButtonColorsPrimary(),
)

With a loading label

kotlin
LoadingButton(
    text = "Sign in",
    onClick = { isLoading = true },
    isLoading = isLoading,
    loadingText = "Signing in",
)

Component States

Disabled State

kotlin
LoadingButton(
    text = "Download",
    onClick = { /* Handle click event */ },
    enabled = false,
)

Properties

LoadingButton

PropertyTypeDescriptionDefault ValueRequired
textStringLabel shown when not loading-Yes
onClick() -> UnitCallback on click; not invoked while loading-Yes
modifierModifierModifier applied to the buttonModifierNo
isLoadingBooleanWhether the button is in the loading statefalseNo
loadingTextString?Label shown next to the dots while loadingnullNo
enabledBooleanWhether the button is enabledtrueNo
cornerRadiusDpCorner radius of the buttonButtonDefaults.CornerRadiusNo
minWidthDpMinimum width of the buttonButtonDefaults.MinWidthNo
minHeightDpMinimum height of the buttonButtonDefaults.MinHeightNo
colorsTextButtonColorsColor configurationButtonDefaults.textButtonColors()No
insideMarginPaddingValuesMargin inside the buttonButtonDefaults.InsideMarginNo
interactionSourceMutableInteractionSource?Interaction source of the buttonnullNo
indicationIndication?Indication of the button (COUI press feedback is built in)nullNo

LoadingButtonDefaults

ConstantTypeDescriptionDefault Value
DotRadiusDpRadius of each loading dot1.dp
DotSpacingDpGap between two neighbouring loading dots2.dp

Behavior

  • While isLoading is true the label is hidden but stays measured, so the button keeps its width; clicks are swallowed while the COUI press feedback (scale + tint) still plays.
  • The three dots pulse 20% -> 50% -> 100% -> 50% -> 20% alpha on a linear curve; each dot is delayed by 333ms and the whole 1332ms wave loops, matching the COUILoadingButton animator set.
  • With loadingText set, the loading state shows that label followed by three animated dot glyphs instead of the plain dot indicator (COUIButton isShowLoadingText).
  • The dots are drawn with the button's content color, like COUILoadingButton draws them with the label paint.

Changelog

Released under the Apache-2.0 License