Skip to content

Commit

Permalink
Restore focusRequester in Slider
Browse files Browse the repository at this point in the history
  • Loading branch information
MatkovIvan committed Dec 9, 2024
1 parent de3f25a commit 950f761
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.lerp
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -170,6 +172,7 @@ fun Slider(
val onValueChangeFinishedState = rememberUpdatedState(onValueChangeFinished)
val tickFractions = remember(steps) { stepsToTickFractions(steps) }

val focusRequester = remember { FocusRequester() }
BoxWithConstraints(
modifier
.minimumInteractiveComponentSize()
Expand All @@ -182,6 +185,7 @@ fun Slider(
valueRange,
steps
)
.focusRequester(focusRequester)
.focusable(enabled, interactionSource)
.slideOnKeyEvents(
enabled,
Expand Down Expand Up @@ -229,6 +233,7 @@ fun Slider(
rememberUpdatedState<(Float) -> Unit> { velocity: Float ->
val current = rawOffset.floatValue
val target = snapValueToTick(current, tickFractions, minPx, maxPx)
focusRequester.requestFocus()
if (current != target) {
scope.launch {
animateToTarget(draggableState, current, target, velocity)
Expand Down

0 comments on commit 950f761

Please sign in to comment.