'Bidirectional Swipe using Swipeable Jetpack Compose
I am using Swipeable in jetpack compose for left to right or right to left swipe gestures. But i am confused if i can pass both of them in a single swipeable method ?
Box(
modifier = Modifier
.fillMaxWidth()
.swipeable(
state = swipeAbleState,
anchors = mapOf(0f to 0, sizePx to 1),
thresholds = { _, _ ->
FractionalThreshold(0.3f)
},
orientation = Orientation.Horizontal
)
This will provide me left to right swipe and similarly if i pass mapOf(0f to 0, -sizePx to 1) in anchor it will provide me right to left swipe now I need to have both of them in my Box is it possible ?
Solution 1:[1]
try: anchors = mapOf(0f to 0, sizePx to 1, -sizePx to -1)
Solution 2:[2]
If you want both left and right then use following anchors:
val anchors = mapOf(0f to 0, sizePx to 1, -sizePx to 2)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ekaterina Banks |
| Solution 2 | Jeevan Rupacha |
