code: private float calculateDy(float distanceY) {
      int currentY = view.getScrollY();
      float nextY = distanceY + currentY;
      boolean isInsideVertically = nextY >= minY && nextY <= maxY;
      return isInsideVertically ? distanceY : 0;
    }
docs: Returns the distance in the Y axes to perform the scroll taking into account the view
  boundary.