isHorizontalScrolling method

bool isHorizontalScrolling(
  1. double mDeltaX,
  2. double mDeltaY
)

Previously, we were determining if mDeltaX > mDeltaY to identify horizontal scroll, but this approach was flawed. It misclassified diagonal scrolls, such as those at 45 degrees, as horizontal scrolls.

To address this, we've introduced a tweak to avoid unintentional horizontal scroll detection. By increasing mDeltaY * 2, we ensure accurate detection even for scenarios involving carousels and PageViews.

This adjustment helps us correctly differentiate between horizontal and diagonal scrolls.

Implementation

bool isHorizontalScrolling(double mDeltaX, double mDeltaY) {
  double mDeltaXAsb = mDeltaX.abs();
  double mDeltaYAsb = mDeltaY.abs();
  final int increaseDeltaYBy =
      2; // The factor by which we adjust mDeltaY for improved scroll detection accuracy.

  // kTouchSlop: "The distance a touch has to travel for the framework to be confident that the gesture is a scroll gesture". Source: constants.dart.
  bool isScrollGesture = mDeltaXAsb > kTouchSlop;
  bool isHorizontalScroll = mDeltaXAsb > (mDeltaYAsb * increaseDeltaYBy); // Determining if the scroll is primarily horizontal while accounting for the adjusted mDeltaY.


  if (isScrollGesture && isHorizontalScroll) {
    return true;
  }
  return false;
}