forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Material3 Stepper to Compose for Wear OS
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 in the middle. Value can be increased and decreased by clicking on the increase and decrease buttons. This version doesn't have range semantics by default. It can be added using modifier such as Modifier.rangeSemantics. Test: androidx.wear.compose.material3.Stepper tests Bug: 266370734 Relnote: "Adding Material3 Stepper to Wear Compose. This version doesn't have range semantics by default. It can be added using modifier such as Modifier.rangeSemantics." Change-Id: Ic39fddeb8f959bdff6aee0ee6b2cbe6c906feab8
- Loading branch information
1 parent
f3c90a3
commit 26f6c2d
Showing
7 changed files
with
1,069 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...-material3/samples/src/main/java/androidx/wear/compose/material3/samples/StepperSample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package androidx.wear.compose.material3.samples | ||
|
||
import androidx.annotation.Sampled | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.wear.compose.material3.Icon | ||
import androidx.wear.compose.material3.Stepper | ||
import androidx.wear.compose.material3.StepperDefaults | ||
import androidx.wear.compose.material3.Text | ||
import androidx.wear.compose.material3.rangeSemantics | ||
|
||
@Sampled | ||
@Composable | ||
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") } | ||
} | ||
|
||
@Sampled | ||
@Composable | ||
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") } | ||
} | ||
|
||
@Sampled | ||
@Composable | ||
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") } | ||
} |
Oops, something went wrong.