handleEvent method

  1. @override
void handleEvent(
  1. PointerEvent event
)
override

Called when a pointer event is routed to this recognizer.

This will be called for every pointer event while the pointer is being tracked. Typically, this recognizer will start tracking the pointer in addAllowedPointer, which means that handleEvent will be called starting with the PointerDownEvent that was passed to addAllowedPointer.

See also:

Implementation

@override
void handleEvent(PointerEvent event) async {
  dragDistance = dragDistance + event.delta;
  if (isWebViewAtScreenTop()) {
    bool horizontalScrolling = false;
    switch (event.runtimeType) {
      case PointerDownEvent:
        mOldPointY = event.position.dy;
        mOldPointX = event.position.dx;
        break;
      case PointerMoveEvent:
        mDeltaX = mOldPointX - event.position.dx;
        mDeltaY = mOldPointY - event.position.dy;
        horizontalScrolling =
            isHorizontalScrolling(mDeltaX, mDeltaY);
        break;
    }

    if (event.runtimeType != PointerMoveEvent) {
      //Don't switch scroll control when not scrolling (pointer moving). This was implemented to prevent a need for an extra down scroll gesture when moving from native into web-content scroll.
      return;
    }

    yGlobal = dragDistance.dy;
    int scrollDirection = getScrollingDirection(mDeltaY);
    if (scrollDirection == _SCROLL_DIRECTION_DOWN) {
      // This works since we run this method inside a condition that the WebView is already at screen top
      canWVContentScrollUp = true;
      //reset our flag for the next time we'll get webViewDidScrollToTop() from ML
      if (didReceiveFromMLScrollToTop) {
        didReceiveFromMLScrollToTop = false;
      }
    }

    if (horizontalScrolling) {
      resolve(GestureDisposition.rejected); // Native internal will win
    } else if (scrollDirection == _SCROLL_DIRECTION_UP &&
        !canWVContentScrollUp) {
      //DeltaY<0 is user trying to scroll up + WebView content cannot scroll up: return touch to Native.
      resolve(GestureDisposition.rejected); // Native internal will win
    } else {
      resolve(GestureDisposition.accepted); // WebView internal will win
//        canWVContentScrollUp = true;
    }
  }
}