SwipeButton

fun SwipeButton(modifier: Modifier = Modifier, state: SwipeButtonState = rememberSwipeButtonState(), isEnabled: Boolean = true, isContentFollow: Boolean = true, cornerRadius: Dp = 12.dp, contentAlphaFactor: Float = 1.5f, widthAnimationSpec: AnimationSpec<Dp> = tween(500), cornerAnimationSpec: AnimationSpec<Dp> = tween(500), restAnimationSpec: AnimationSpec<Float> = spring(stiffness = Spring.StiffnessLow), completeAnimationSpec: AnimationSpec<Float> = tween(300), resetAnimationSpec: AnimationSpec<Float> = tween(300), background: @Composable (enabled: Boolean) -> Unit = {}, content: @Composable (progress: Float) -> Unit, indicator: @Composable (progress: Float) -> Unit, completedContent: @Composable () -> Unit)

This component features smooth animations, state management, and transitions between idle and completed states (where the button collapses into a circular progress indicator).

Parameters

modifier

The Modifier to be applied to the root layout.

state

The state object SwipeButtonState to control and observe the button's progress.

isEnabled

Whether the button is interactive. If false, drag gestures are disabled.

isContentFollow

Whether the background content should translate horizontally as the user swipes.

cornerRadius

The initial corner radius of the button container.

contentAlphaFactor

Controls how quickly the background content fades out during the swipe.

widthAnimationSpec

Animation spec for the width transition when reaching the completed state.

cornerAnimationSpec

Animation spec for the corner radius transition.

restAnimationSpec

Animation spec for the "spring back" effect when a swipe is released before the threshold.

completeAnimationSpec

Animation spec for the final progress movement to 100%.

resetAnimationSpec

Animation spec for resetting the button state.

background

Composable for the button's background layer.

content

Composable for the main text or instruction, providing the current swipe progress (0f-1f).

indicator

Composable for the draggable handle, providing the current swipe progress.

completedContent

Composable displayed when the button is in the SwipeButtonState.isCompleted state.