Use enum for swipe states

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-11-02 01:10:19 +05:30
parent 3f223f4306
commit 78f15ac7d9
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80

View file

@ -34,6 +34,11 @@ import dev.msfjarvis.lobsters.model.Submitter
import dev.msfjarvis.lobsters.ui.theme.LobstersTheme
import dev.msfjarvis.lobsters.ui.theme.titleColor
private enum class SwipeState {
NotSwiped,
FullySwiped,
}
@Composable
fun LazyItemScope.LobstersItem(
post: LobstersPost,
@ -45,11 +50,11 @@ fun LazyItemScope.LobstersItem(
val width = with(DensityAmbient.current) {
ConfigurationAmbient.current.screenWidthDp.toDp().toPx()
}
val swipeableState = rememberSwipeableState("Not Swiped")
val anchors = mapOf(0f to "Not Swiped", width to "Fully Swiped")
val swipeableState = rememberSwipeableState(SwipeState.NotSwiped)
val anchors = mapOf(0f to SwipeState.NotSwiped, width to SwipeState.FullySwiped)
if (swipeableState.offset.value >= (width / 2)) {
saveAction.invoke(post)
swipeableState.animateTo("Not Swiped")
swipeableState.animateTo(SwipeState.NotSwiped)
}
Column(