[FEAT] Scroll only in one direction
fred-bowker opened this issue · comments
Hi,
A massive thanks for creating this pager, it's really useful.
One feature that would be good is for a setting to only swipe in one direction, so basically I want to be able to swipe cards forward but never backwards, if you can give me a couple of pointers for where I could do this I could give it a go at coding myself. I think this feature would be useful to the component.
I had a look in the code and I think the change can be made in
extension Pager {
var swipeGesture: some Gesture {
DragGesture(minimumDistance: minimumDistance)
.onChanged({ value in
if isLeftToRightGesture(value) {
self.onDragChanged(with: value)
}
})
.onEnded({ (value) in
if isLeftToRightGesture(value) {
self.onDragGestureEnded()
}
})
}
private func isLeftToRightGesture(_ value: DragGesture.Value) -> Bool {
return !((value.location.x - value.startLocation.x) > 0)
}
}
Cheers, Fred
Hi @fred-bowker , thanks for the kind words but especially for the feature request and the possible implementation. You're right, the change should be done. You might wanna check how that works with a vertical Pager
but it should be fine as that just a Pager
that's rotated.
If you're okay with it, send a PR and I'll take a look and make or suggest changes on top of it. As a user, I'd expect a modifier that accepts an optional enum
with values forwards
and backwards
and then convenience modifiers forwards
and backwards
(similar to horizontal
and vertical
although the naming in this case might be confusing).
Anyways, that's a conversation for later, I'm open to suggestions. Happy to review a PR, thanks again