Halil Ozercan
05/21/2021, 11:23 PMswipeable
modifier. However, swipeable
accepts a predefined map of anchors which are limited unless the developer wants to put thousands of anchor points in there. Instead, I reset the swipe state everytime it gets settled and aggregate the total swipe amount. My question; is there a canonical way of doing this snapping behavior without swipeable?Halil Ozercan
05/21/2021, 11:26 PMval swipeableState = rememberSwipeableState(initialValue = 0)
var daysOffset by remember { mutableStateOf(0) }
val progress = swipeableState.progress
LaunchedEffect(progress) {
if (progress.fraction == 1f && <http://progress.to|progress.to> == progress.from) {
daysOffset -= <http://progress.to|progress.to>
swipeableState.snapTo(0)
}
}
Halil Ozercan
05/21/2021, 11:28 PM.swipeable(
state = swipeableState,
anchors = (-7..7)
.map {
it * (24 * 3600 / secondPerPixel) to it
}
.toMap(),
orientation = Orientation.Horizontal
)
Only 7 anchors are enough because view is limited by a week. If there is no swipe reset, scrolling would completely stop in one week range.Doris Liu
05/22/2021, 12:18 AMswipeable
API, you might want to reach for a lower level API. In this case, I'd recommend dragable
and Animatable
. It may not be that much more code than the hack you have right now. 😛 At the end of the drag, you'd need to use that velocity to calculate the natural stopping point, find the closest anchor among any number of anchors that you might have, and animateTo
it. In fact, there's a good example in the animation codelab for this.Doris Liu
05/22/2021, 12:23 AMDoris Liu
05/22/2021, 12:49 AMscrollable
with a custom FlingBehavior
🙂Halil Ozercan
05/22/2021, 6:31 AMHalil Ozercan
05/23/2021, 9:02 PMswipeable.progress
.Doris Liu
05/25/2021, 12:05 AM