# swipe-to-reveal

Published articles for swipe-to-reveal.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Swipe to reveal in Jetpack Compose

DevFeed: [Swipe to reveal in Jetpack Compose](<https://devfeed.tech/articles/swipe-to-reveal-in-jetpack-compose-25899.md>)

Original publisher: [Read original article](<https://proandroiddev.com/swipe-to-reveal-in-jetpack-compose-6ffa8928a4c2?source=rss-56174fa84bcc------2>)

Author: Denys Rudenko

Published: 2021-02-19T17:21:58Z

Content type: tutorial

Language: en

Sources: [Stories by Denis Rudenko on Medium](<https://devfeed.tech/sources/stories-by-denis-rudenko-on-medium.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [Compose](<https://devfeed.tech/topics/compose.md>), [draggable](<https://devfeed.tech/topics/draggable.md>), [ui](<https://devfeed.tech/topics/ui.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [compose](<https://devfeed.tech/tags/compose.md>), [compose-animation](<https://devfeed.tech/tags/compose-animation.md>), [draggable](<https://devfeed.tech/tags/draggable.md>), [gestures](<https://devfeed.tech/tags/gestures.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [stateflow](<https://devfeed.tech/tags/stateflow.md>), [swipe-to-reveal](<https://devfeed.tech/tags/swipe-to-reveal.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

### AI overview

A tutorial showing how to implement swipe-to-reveal cards in Jetpack Compose by detecting horizontal drag gestures and managing revealed card state with a view model and StateFlow.

### Source excerpt

Swipe to dismiss is really easy to implement in compose, including item removal animation by using a combination of SwipeToDismiss & AnimatedVisibility composables. SwipeToDismiss doesn't allow us to stop the dragging motion midway though, so let's take a look how we can achieve the following by detecting horizontal drag gestures on any composable. https://medium.com/media/1a355b2d3e397414c51442342f16cda5/hrefStep 1: Creating a data source Those who've read expandable lists in jetpack compose can skip this step, since data source is almost the same. First we define our model to hold the card related info: data class CardModel(val id: Int, val title: String) We'll be using AAC viewModel example here, but feel free to use any "controller" abstraction you prefer. https://medium.com/media/28ca457093268969ac4f2e179ee860ef/href This class serves 5 purposes: Holds list of cards using MutableStateFlow in _cards field, and exposes a StateFlow to observers via cards field. Holds list of "revealed" card ids in _revealedCardIdsList, and exposes them to observers via revealedCardIdsList field. Provides list of cards using getFakeData() function. We need a coroutine here, to emit the testList into _cards. Has onItemExpanded() to mark cards as revealed, by adding tapped card id to _revealedCardIdsList, and notify observers about this change by mutating the state of _revealedCardIdsList. Has onItemCollapsed() to remove revealed card id from _revealedCardIdsList, and notify observers about this change by mutating the state of _revealedCardIdsList. Step 2: CardsScreen composablehttps://medium.com/media/4505fde17b0e8f9672f392cb9b3296f3/href We are observing the viewModel.cards containing our list of cards, and viewModel.expandedCardIds with the help of .collectAsStateWithLifecycle(). UI is quite simple here, each list item is represented with a Box that contains our hidden action icons & the draggable card. ActionsRow -- row with 3 icons, exposes callbacks from each icon tap: onDelete,