Merge "Optimizing default track and thumb" into androidx-main
diff --git a/compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/SliderSample.kt b/compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/SliderSample.kt
index cfee610..4e1f2c5 100644
--- a/compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/SliderSample.kt
+++ b/compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/SliderSample.kt
@@ -149,6 +149,7 @@
fun SliderWithCustomTrackAndThumb() {
var sliderPosition by remember { mutableStateOf(0f) }
val interactionSource = MutableInteractionSource()
+ val colors = SliderDefaults.colors(thumbColor = Color.Red, activeTrackColor = Color.Red)
Column {
Text(text = sliderPosition.toString())
Slider(
@@ -164,12 +165,12 @@
thumb = {
SliderDefaults.Thumb(
interactionSource = interactionSource,
- colors = SliderDefaults.colors(thumbColor = Color.Red)
+ colors = colors
)
},
track = { sliderPositions ->
SliderDefaults.Track(
- colors = SliderDefaults.colors(activeTrackColor = Color.Red),
+ colors = colors,
sliderPositions = sliderPositions
)
}
diff --git a/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Slider.kt b/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Slider.kt
index b76ab43..61299ed 100644
--- a/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Slider.kt
+++ b/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Slider.kt
@@ -173,20 +173,20 @@
>
colors = colors,
interactionSource = interactionSource,
- thumb = {
+ thumb = remember(interactionSource, colors, enabled) { {
SliderDefaults.Thumb(
interactionSource = interactionSource,
colors = colors,
enabled = enabled
)
- },
- track = { sliderPositions ->
+ } },
+ track = remember(colors, enabled) { { sliderPositions ->
SliderDefaults.Track(
colors = colors,
enabled = enabled,
sliderPositions = sliderPositions
)
- }
+ } }
)
}
@@ -256,13 +256,13 @@
colors = colors,
interactionSource = interactionSource,
thumb = thumb,
- track = { sliderPositions ->
+ track = remember(colors, enabled) { { sliderPositions ->
SliderDefaults.Track(
colors = colors,
enabled = enabled,
sliderPositions = sliderPositions
)
- }
+ } }
)
}
@@ -321,13 +321,14 @@
onValueChangeFinished: (() -> Unit)? = null,
colors: SliderColors = SliderDefaults.colors(),
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
- thumb: @Composable (SliderPositions) -> Unit = {
- SliderDefaults.Thumb(
- colors = colors,
- enabled = enabled,
- interactionSource = interactionSource
- )
- }
+ thumb: @Composable (SliderPositions) -> Unit =
+ remember(interactionSource, colors, enabled) { {
+ SliderDefaults.Thumb(
+ interactionSource = interactionSource,
+ colors = colors,
+ enabled = enabled
+ )
+ } }
) {
require(steps >= 0) { "steps should be >= 0" }