Swipe Button using Jetpack Compose
--
SwipeIndicator
Let's start by creating the button we will use to trigger the swipe action.
A simple box with white background and a right chevron icon.
SwipeButton
We will use swipeable
Modifier
for the swipe action handling.
swipeableState.currentValue = 0
means the button is in its initial position and swipeableState.currentValue = 1
means the swipe action is completed.
We will use this logic along with LaunchedEffect
to determine the swipe complete.
I have used FractionalThreshold
of 0.3
. This means if we swipe less than 30% of the width, the indicator will snap back to the initial state. If swipe more than that threshold, the indicator snaps to the final position.
SwipeButtonSample
And finally, an example to demonstrate how to use the button.
We can use the onSwipe
handler to make network calls, database operations, or any other required actions.
The delay
is used to simulate any such operation we would be using in the actual app.
Please comment with your valuable feedback. It would help me to improvise.
Kindly 👏👏👏 if this was useful.
Please follow if you would like to see more content related to Android Jetpack Compose.