globulus / swiftui-pull-to-refresh

Pull to refresh functionality for any ScrollView in SwiftUI!
MIT License
277 stars 51 forks source link

Accidentally triggering the Pull to refresh action. #14

Open darecki opened 2 years ago

darecki commented 2 years ago

If the scroll view has bouncing enabled it is very easy to accidentally trigger a pull to refresh action while scrolling the view up. The view will bounce using the momentum and velocity, reaching the threshold and thus triggering the action.

I think it should only be triggered while a user is dragging the view down (still touching the screen with their finger).

gordan-glavas-codecons commented 2 years ago

There's no apparent good way to detect when touches begin or end on a ScrollView, since this is usually done with a DragGesture, which then in turn overrides the scrolling behaviour.

You could track how fast the user's scrolling and use that data to figure out if a bounce happened, but that seems brittle. I'll give this some more thought.

SApolinario commented 2 years ago

I'm running into the same issue but unsure how to solve it. You guys come up with any ideas? Thanks.

gordan-glavas-codecons commented 2 years ago

I tried everything I could think of to try to track if the user's actually touching the screen while pulling, but various gestures either get hijacked by the ScrollView (at least in the onEnded part) or interfere with regular scroll.

I also tried figuring out if a bounce happened by analyzing a snapshot of the latest scroll positions to detect if there's been a sudden change in scrolling direction, but it has too many false positives.

I guess you can always turn bouncing off.

VansonLeung commented 2 years ago

How about using introspect to keep track of scrollview state? That way you could know the touches

globulus commented 2 years ago

I'll give that a try but I'm not sure if we want to make a dependency on the introspect lib as it's not maintained as much anymore. Let me know if this that big of an issue for you guys.