New Compose Multiplatform components arrived on Composables UICheck it out →

Component in Wear Material 3 Compose

Stepper

Android

[Stepper] allows users to make a selection from a range of values. It's a full-screen control with increase button on the top, decrease button on the bottom and a slot (expected to have either [Text] or [Button]) in the middle. Value can be increased and decreased by clicking on the increase and decrease buttons. Buttons can have custom icons - [decreaseIcon] and [increaseIcon]. Step value is calculated as the difference between min and max values divided by [steps]+1. Stepper itself doesn't show the current value but can be displayed via the content slot or [PositionIndicator] if required. If [value] is not equal to any step value, then it will be coerced to the closest step value. However, the [value] itself will not be changed and [onValueChange] in this case will not be triggered. To add range semantics on Stepper, use [Modifier.rangeSemantics].

Last updated:

Installation

dependencies {
   implementation("androidx.wear.compose:compose-material3:1.0.0-alpha23")
}

Overloads

@Composable
@ExperimentalWearMaterial3Api
fun Stepper(
    value: Float,
    onValueChange: (Float) -> Unit,
    steps: Int,
    decreaseIcon: @Composable () -> Unit,
    increaseIcon: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    valueRange: ClosedFloatingPointRange<Float> = 0f..(steps + 1).toFloat(),
    backgroundColor: Color = MaterialTheme.colorScheme.background,
    contentColor: Color = MaterialTheme.colorScheme.onSurface,
    iconColor: Color = contentColor,
    content: @Composable BoxScope.() -> Unit
)

Parameters

namedescription
valueCurrent value of the Stepper. If outside of [valueRange] provided, value will be coerced to this range.
onValueChangeLambda in which value should be updated
stepsSpecifies the number of discrete values, excluding min and max values, evenly distributed across the whole value range. Must not be negative. If 0, stepper will have only min and max values and no steps in between
decreaseIconA slot for an icon which is placed on the decrease (bottom) button
increaseIconA slot for an icon which is placed on the increase (top) button
modifierModifiers for the Stepper layout
valueRangeRange of values that Stepper value can take. Passed [value] will be coerced to this range
backgroundColor[Color] representing the background color for the stepper.
contentColor[Color] representing the color for [content] in the middle.
iconColorIcon tint [Color] which used by [increaseIcon] and [decreaseIcon] that defaults to [contentColor], unless specifically overridden.
contentContent body for the Stepper.
@Composable
@ExperimentalWearMaterial3Api
fun Stepper(
    value: Int,
    onValueChange: (Int) -> Unit,
    valueProgression: IntProgression,
    decreaseIcon: @Composable () -> Unit,
    increaseIcon: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    backgroundColor: Color = MaterialTheme.colorScheme.background,
    contentColor: Color = MaterialTheme.colorScheme.onSurface,
    iconColor: Color = contentColor,
    content: @Composable BoxScope.() -> Unit
)

Parameters

namedescription
valueCurrent value of the Stepper. If outside of [valueProgression] provided, value will be coerced to this range.
onValueChangeLambda in which value should be updated
valueProgressionProgression of values that Stepper value can take. Consists of rangeStart, rangeEnd and step. Range will be equally divided by step size
decreaseIconA slot for an icon which is placed on the decrease (bottom) button
increaseIconA slot for an icon which is placed on the increase (top) button
modifierModifiers for the Stepper layout
backgroundColor[Color] representing the background color for the stepper.
contentColor[Color] representing the color for [content] in the middle.
iconColorIcon tint [Color] which used by [increaseIcon] and [decreaseIcon] that defaults to [contentColor], unless specifically overridden.
contentContent body for the Stepper.

Code Examples

StepperSample

@Composable
@OptIn(ExperimentalWearMaterial3Api::class
@Sampled
fun StepperSample() {
    var value by remember { mutableStateOf(2f) }
    Stepper(
        value = value,
        onValueChange = { value = it },
        valueRange = 1f..4f,
        increaseIcon = { Icon(StepperDefaults.Increase, "Increase") },
        decreaseIcon = { Icon(StepperDefaults.Decrease, "Decrease") },
        steps = 7
    ) { Text("Value: $value") }
}

StepperWithRangeSemanticsSample

@Composable
@OptIn(ExperimentalWearMaterial3Api::class
@Sampled
fun StepperWithRangeSemanticsSample() {
    var value by remember { mutableStateOf(2f) }
    val valueRange = 1f..4f
    val onValueChange = { i: Float -> value = i }
    val steps = 7

    Stepper(
        value = value,
        onValueChange = onValueChange,
        valueRange = valueRange,
        modifier = Modifier.rangeSemantics(value, true, onValueChange, valueRange, steps),
        increaseIcon = { Icon(StepperDefaults.Increase, "Increase") },
        decreaseIcon = { Icon(StepperDefaults.Decrease, "Decrease") },
        steps = steps,
    ) { Text("Value: $value") }
}

StepperWithIntegerSample

@Composable
@OptIn(ExperimentalWearMaterial3Api::class
@Sampled
fun StepperWithIntegerSample() {
    var value by remember { mutableStateOf(2) }
    Stepper(
        value = value,
        onValueChange = { value = it },
        increaseIcon = { Icon(StepperDefaults.Increase, "Increase") },
        decreaseIcon = { Icon(StepperDefaults.Decrease, "Decrease") },
        valueProgression = 1..10
    ) { Text("Value: $value") }
}