You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -80,16 +80,71 @@ You can easily implement a slide-to-unlock feature using the `SlideToUnlock` com
80
80
81
81
The `SlideToUnlock` composable exposes relevant state parameters, allowing you to hoist the slide status and track when the slide action is completed via a callback.
82
82
83
-
-`isSlided`: A `Boolean` state that controls the component's state. When `true`, the thumb moves to the end and becomes disabled.
84
-
-`onSlideCompleted`: A lambda that is invoked when the user successfully slides the thumb to the end. You should typically use this to update your `isSlided` state.
83
+
-`state`: A `SlideState` value that controls the component. `SlideState.Idle` keeps the thumb draggable; `Loading`, `Success` and `Error` lock the thumb at the end of the track and show the matching indicator.
84
+
-`onSlideCompleted`: A lambda that is invoked when the user successfully slides the thumb to the end (or activates the component via an accessibility action / keyboard). You should typically use this to move your `state` to `SlideState.Loading`.
85
85
86
86
```kotlin
87
-
varisSlided by remember { mutableStateOf(false) }
87
+
varslideState by remember { mutableStateOf(SlideState.Idle) }
> If you're upgrading from a previous version, the `SlideToUnlock(isSlided: Boolean, ...)` overload still exists but is deprecated — `isSlided = true` maps to `SlideState.Loading`. Migrate to the `state`-based API to use the success and error states.
136
+
137
+
### Accessibility & Keyboard Support
138
+
139
+
The track exposes a `Role.Button` semantics node with a state description derived from `HintTexts`. While `state` is `Idle`, it also publishes an accessibility "click" action (labeled by the `actionLabel` parameter) and is focusable, so pressing **Enter** or **Space** while focused triggers `onSlideCompleted` — the same as completing the gesture. Provide a `contentDescription` to override the default announcement, and set `animationsEnabled = false` (e.g. from your "reduce motion" preference) to make the thumb snap between positions and the hint switch without a cross-fade.
140
+
141
+
```kotlin
142
+
SlideToUnlock(
143
+
state = slideState,
144
+
actionLabel ="Confirm",
145
+
contentDescription ="Confirm your action by sliding the thumb to the end",
You can customize all colors of the component by leveraging an instance of `DefaultSlideToUnlockColors`, which contains some prebuilt behaviors for providing proper color sets depending on the states, and you can pass it to the `colors` parameter. This allows you to style the track, hint text, thumb, and progress indicator to match your app's theme.
99
154
100
155
```kotlin
101
-
varisSlided by remember { mutableStateOf(false) }
156
+
varslideState by remember { mutableStateOf(SlideState.Idle) }
@@ -209,18 +264,18 @@ private class MaterialThemedSlideToUnlockColors : SlideToUnlockColors {
209
264
The text displayed in the track can be customized by passing a `HintTexts` object. This allows you to define different messages for the initial state and the final "slided" state.
210
265
211
266
```kotlin
212
-
varisSlided by remember { mutableStateOf(false) }
267
+
varslideState by remember { mutableStateOf(SlideState.Idle) }
@@ -230,47 +285,49 @@ For complete control over the appearance and behavior of the thumb and hint, you
230
285
231
286
#### Customizing the Thumb
232
287
233
-
The `thumb` slot provides you with the `isSlided` state, the current `slideFraction`, the `colors` object, and the `thumbSize`. You can use these to create dynamic and interactive thumbs.
288
+
The `thumb` slot provides you with the current `state` (`SlideState`), the current `slideFraction`, the `colors` object, the `thumbSize`, and the `orientation`. You can use these to create dynamic and interactive thumbs.
234
289
235
-
This example replaces the default arrow icon with a rotating app icon and shows a success checkmark when completed.
290
+
This example replaces the default arrow icon with a rotating restore icon and shows a success checkmark when the action completes.
236
291
237
292
```kotlin
238
-
var isSlided by remember { mutableStateOf(false) }
239
-
var isCompleted by remember { mutableStateOf(false) }
293
+
var slideState by remember { mutableStateOf(SlideState.Idle) }
240
294
241
-
LaunchedEffect(isSlided) {
242
-
if (isSlided) {
295
+
LaunchedEffect(slideState) {
296
+
if (slideState ==SlideState.Loading) {
243
297
delay(1500) // Simulate in-app purchases or any tasks
0 commit comments