noties / Scrollable

Android scrollable tabs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ghost click events propagated to the scrolling view

noties opened this issue · comments

If UP event received when getScrollY() == mMaxScrollY, click event is propagated to the scrolling view

I handle the problem like this.Maybe help someone,but this not a very good solution.
private int oldScrollY=0;
private int moveStartY=0;
@OverRide
public boolean dispatchTouchEvent(@SuppressWarnings("NullableProblems") MotionEvent event) {

    if (mSelfUpdateScroll) {
        mIsTouchOngoing = false;
        mIsDraggingDraggable = false;
        mIsScrolling = false;
        mIsFlinging = false;
        removeCallbacks(mIdleRunnable);
        removeCallbacks(mScrollRunnable);
        return super.dispatchTouchEvent(event);
    }

    final int action = event.getActionMasked();
    if (action == MotionEvent.ACTION_DOWN) {
        if (getScrollY()>=mMaxScrollY){
            oldScrollY=0;
        }
        moveStartY=0;
        mIsTouchOngoing = true;
        mScroller.abortAnimation();

        if (mDraggableView != null && mDraggableView.getGlobalVisibleRect(mDraggableRect)) {
            final int x = (int) (event.getRawX() + .5F);
            final int y = (int) (event.getRawY() + .5F);
            mIsDraggingDraggable = mDraggableRect.contains(x, y);
        } else {
            mIsDraggingDraggable = false;
        }
    } else if (action == MotionEvent.ACTION_UP
            || action == MotionEvent.ACTION_CANCEL) {
        moveStartY=0;
        mIsTouchOngoing = false;

        if (mCloseUpAlgorithm != null) {
            removeCallbacks(mIdleRunnable);
            postDelayed(mIdleRunnable, mConsiderIdleMillis);
        }
    }else if(action==MotionEvent.ACTION_MOVE){
        if (getScrollY()<mMaxScrollY) {
            oldScrollY = getScrollY();
        }else if (getScrollY()==mMaxScrollY){
            if (moveStartY==0){
                moveStartY= (int) event.getRawY();
            }else if (moveStartY-event.getRawY()>100){
                oldScrollY=0;
            }
        }
    }

    final boolean isPrevScrolling = mIsScrolling;
    final boolean isPrevFlinging = mIsFlinging;

    mIsFlinging = mFlingDetector.onTouchEvent(event);
    mIsScrolling = mScrollDetector.onTouchEvent(event);

    removeCallbacks(mScrollRunnable);
    post(mScrollRunnable);

    final boolean isIntercepted = mIsScrolling || mIsFlinging;
    final boolean isPrevIntercepted = isPrevScrolling || isPrevFlinging;

    final boolean shouldRedirectDownTouch = action == MotionEvent.ACTION_MOVE
            && (!isIntercepted && isPrevIntercepted)
            && getScrollY() == mMaxScrollY;

    if (isIntercepted || isPrevIntercepted) {

        mMotionEventHook.hook(event, MotionEvent.ACTION_CANCEL);

        if (!isPrevIntercepted) {
            return true;
        }
    }

    if (shouldRedirectDownTouch) {
        mMotionEventHook.hook(event, MotionEvent.ACTION_DOWN);
    }
    if (action == MotionEvent.ACTION_UP
            || action == MotionEvent.ACTION_CANCEL){
        moveStartY=0;
        if (getScrollY()==mMaxScrollY&&(mMaxScrollY-oldScrollY<200)){
            oldScrollY=0;
            return true;
        }
    }

    super.dispatchTouchEvent(event);
    return true;
}

I have fixed it, it's in pull request already: #46