Stepper

Functions summary

Unit
@Composable
Stepper(
    value: Int,
    onValueChange: (Int) -> Unit,
    valueProgression: IntProgression,
    decreaseIcon: @Composable () -> Unit,
    increaseIcon: @Composable () -> Unit,
    modifier: Modifier,
    backgroundColor: Color,
    contentColor: Color,
    iconColor: Color,
    enableRangeSemantics: Boolean,
    content: @Composable BoxScope.() -> Unit
)

Stepper allows users to make a selection from a range of values.

Unit
@Composable
Stepper(
    value: Float,
    onValueChange: (Float) -> Unit,
    steps: Int,
    decreaseIcon: @Composable () -> Unit,
    increaseIcon: @Composable () -> Unit,
    modifier: Modifier,
    valueRange: ClosedFloatingPointRange<Float>,
    backgroundColor: Color,
    contentColor: Color,
    iconColor: Color,
    enableRangeSemantics: Boolean,
    content: @Composable BoxScope.() -> Unit
)

Stepper allows users to make a selection from a range of values.

Functions

@Composable
fun Stepper(
    value: Int,
    onValueChange: (Int) -> Unit,
    valueProgression: IntProgression,
    decreaseIcon: @Composable () -> Unit,
    increaseIcon: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    backgroundColor: Color = MaterialTheme.colors.background,
    contentColor: Color = contentColorFor(backgroundColor),
    iconColor: Color = contentColor,
    enableRangeSemantics: Boolean = true,
    content: @Composable BoxScope.() -> Unit
): Unit

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 Chip) 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. Stepper itself doesn't show the current value but can be displayed via the content slot or PositionIndicator if required.

import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.Stepper
import androidx.wear.compose.material.StepperDefaults
import androidx.wear.compose.material.Text

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")
}

A number of steps is calculated as the difference between max and min values of valueProgression divided by valueProgression.step - 1. For example, with a range of 100..120 and a step 5, number of steps will be (120-100)/ 5 - 1 = 3. Steps are 100(first), 105, 110, 115, 120(last)

If valueProgression range is not equally divisible by valueProgression.step, then valueProgression.last will be adjusted to the closest divisible value in the range. For example, 1..13 range and a step = 5, steps will be 1(first) , 6 , 11(last)

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.

Parameters
value: Int

Current value of the Stepper. If outside of valueProgression provided, value will be coerced to this range.

onValueChange: (Int) -> Unit

Lambda in which value should be updated

valueProgression: IntProgression

Progression of values that Stepper value can take. Consists of rangeStart, rangeEnd and step. Range will be equally divided by step size

decreaseIcon: @Composable () -> Unit

A slot for an icon which is placed on the decrease (bottom) button

increaseIcon: @Composable () -> Unit

A slot for an icon which is placed on the increase (top) button

modifier: Modifier = Modifier

Modifiers for the Stepper layout

backgroundColor: Color = MaterialTheme.colors.background

Color representing the background color for the stepper.

contentColor: Color = contentColorFor(backgroundColor)

Color representing the color for content in the middle.

iconColor: Color = contentColor

Icon tint Color which used by increaseIcon and decreaseIcon that defaults to contentColor, unless specifically overridden.

enableRangeSemantics: Boolean = true

Boolean to decide if default stepper semantics should be enabled. Set to false to disable default stepper range semantics. Alternatively to customize semantics set this value as false and chain new semantics to the modifier.

content: @Composable BoxScope.() -> Unit

Content body for the Stepper.

@Composable
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.colors.background,
    contentColor: Color = contentColorFor(backgroundColor),
    iconColor: Color = contentColor,
    enableRangeSemantics: Boolean = true,
    content: @Composable BoxScope.() -> Unit
): Unit

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 Chip) 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.

import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.Stepper
import androidx.wear.compose.material.StepperDefaults
import androidx.wear.compose.material.Text

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")
}
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.Stepper
import androidx.wear.compose.material.StepperDefaults
import androidx.wear.compose.material.Text

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,
    enableRangeSemantics = false,
) {
    Text("Value: $value")
}
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.Stepper
import androidx.wear.compose.material.StepperDefaults
import androidx.wear.compose.material.Text

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.customSemantics(value, true, onValueChange, valueRange, steps),
    increaseIcon = { Icon(StepperDefaults.Increase, "Increase") },
    decreaseIcon = { Icon(StepperDefaults.Decrease, "Decrease") },
    steps = steps,
    enableRangeSemantics = false,
) {
    Text("Value: $value")
}
Parameters
value: Float

Current value of the Stepper. If outside of valueRange provided, value will be coerced to this range.

onValueChange: (Float) -> Unit

Lambda in which value should be updated

steps: Int

Specifies 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

decreaseIcon: @Composable () -> Unit

A slot for an icon which is placed on the decrease (bottom) button

increaseIcon: @Composable () -> Unit

A slot for an icon which is placed on the increase (top) button

modifier: Modifier = Modifier

Modifiers for the Stepper layout

valueRange: ClosedFloatingPointRange<Float> = 0f..(steps + 1).toFloat()

Range of values that Stepper value can take. Passed value will be coerced to this range

backgroundColor: Color = MaterialTheme.colors.background

Color representing the background color for the stepper.

contentColor: Color = contentColorFor(backgroundColor)

Color representing the color for content in the middle.

iconColor: Color = contentColor

Icon tint Color which used by increaseIcon and decreaseIcon that defaults to contentColor, unless specifically overridden.

enableRangeSemantics: Boolean = true

Boolean to decide if range semantics should be enabled. Set to false to disable default stepper range semantics. Alternatively to customize semantics set this value as false and chain new semantics to the modifier.

content: @Composable BoxScope.() -> Unit

Content body for the Stepper.