mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-18 03:17:03 +05:30
Use enum for swipe states
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
3f223f4306
commit
78f15ac7d9
1 changed files with 8 additions and 3 deletions
|
@ -34,6 +34,11 @@ import dev.msfjarvis.lobsters.model.Submitter
|
||||||
import dev.msfjarvis.lobsters.ui.theme.LobstersTheme
|
import dev.msfjarvis.lobsters.ui.theme.LobstersTheme
|
||||||
import dev.msfjarvis.lobsters.ui.theme.titleColor
|
import dev.msfjarvis.lobsters.ui.theme.titleColor
|
||||||
|
|
||||||
|
private enum class SwipeState {
|
||||||
|
NotSwiped,
|
||||||
|
FullySwiped,
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LazyItemScope.LobstersItem(
|
fun LazyItemScope.LobstersItem(
|
||||||
post: LobstersPost,
|
post: LobstersPost,
|
||||||
|
@ -45,11 +50,11 @@ fun LazyItemScope.LobstersItem(
|
||||||
val width = with(DensityAmbient.current) {
|
val width = with(DensityAmbient.current) {
|
||||||
ConfigurationAmbient.current.screenWidthDp.toDp().toPx()
|
ConfigurationAmbient.current.screenWidthDp.toDp().toPx()
|
||||||
}
|
}
|
||||||
val swipeableState = rememberSwipeableState("Not Swiped")
|
val swipeableState = rememberSwipeableState(SwipeState.NotSwiped)
|
||||||
val anchors = mapOf(0f to "Not Swiped", width to "Fully Swiped")
|
val anchors = mapOf(0f to SwipeState.NotSwiped, width to SwipeState.FullySwiped)
|
||||||
if (swipeableState.offset.value >= (width / 2)) {
|
if (swipeableState.offset.value >= (width / 2)) {
|
||||||
saveAction.invoke(post)
|
saveAction.invoke(post)
|
||||||
swipeableState.animateTo("Not Swiped")
|
swipeableState.animateTo(SwipeState.NotSwiped)
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue