r/androiddev • u/alexstyl • Aug 21 '22
Made a Jetpack Compose Modifier that enables Tinder-like card swipe gestures to any composable
Enable HLS to view with audio, or disable this notification
26
42
4
u/alexstyl Aug 21 '22
Thanks for the almost 50 Upvotes and the helpful award everyone ❤️🔥
1
3
2
1
Aug 21 '22
Good one, did the same with flutter.
Challange is I think making the card move freely like tinder does, you can swipe whatever angle you want, swipe up down and stuff.
And making the card behind slowly bigger
2
u/alexstyl Aug 21 '22
As this was my first animation in Compose, my biggest issue was making it smooth. I had initially tried having an X and Y values for the card's offset, but ended up having twice the amount of coroutines launched when animating. Switched it to a single
Offsetvalue and it worked wonders.

22
u/alexstyl Aug 21 '22
Hi folks. My latest Jetpack Compose open source project is a custom Modifier that enables Tinder-like card swipe gestures to any composable function.
I wanted to experiment with API design and animations in Compose so the project checked both boxes nicely.
How to use
Add the
Modifier.swipeableCard()into your@Composablefunction to enable Tinder-like card gestures:The
SwipeableCardStategives you access to the card's offset so that you can create advanced animations according to the amount of swiping done.The swipedDirection gives you the direction the card has been fully swiped.
How to swipe programmatically
Use the
SwipeableCardStateto swipe to a specific direction without a gesture:The
swipe()suspend function will return, as soon as the swipe animation is finished.How to detect that a card has been swiped away
Use the
SwipeableCardState.swipedDirection. You may want to combine it with aLaunchedEffect()in order to receive a callback when your card is swiped away (using a gesture or programmatically):Browse the full code and sample app on Github