Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug:滑动过程中可能触发点击事件 #828

Open
xiaojianli opened this issue Apr 14, 2023 · 3 comments
Open

Bug:滑动过程中可能触发点击事件 #828

xiaojianli opened this issue Apr 14, 2023 · 3 comments

Comments

@xiaojianli
Copy link

xiaojianli commented Apr 14, 2023

CalendarLayout#onTouchEvent 中

    case MotionEvent.ACTION_MOVE:
            getPointerIndex(event, mActivePointerId);
            if (mActivePointerId == INVALID_POINTER) {
                //如果切换了手指,那把mLastY换到最新手指的y坐标即可,核心就是让下面的 dy== 0,避免抖动
                mLastY = y;
                mActivePointerId = ACTIVE_POINTER;
            }
            float dy = y - mLastY;

            //向上滑动,并且contentView平移到最大距离,显示周视图
            if (dy < 0 && mContentView.getTranslationY() == -mContentViewTranslateY) {
                mLastY = y;

                event.setAction(MotionEvent.ACTION_DOWN);
                dispatchTouchEvent(event);
                mWeekPager.setVisibility(VISIBLE);
                mMonthView.setVisibility(INVISIBLE);
                if (!isWeekView && mDelegate.mViewChangeListener != null) {
                    mDelegate.mViewChangeListener.onViewChange(false);
                }
                isWeekView = true;
                return true;
            }
            hideWeek(false);

            //向下滑动,并且contentView已经完全平移到底部
            if (dy > 0 && mContentView.getTranslationY() + dy >= 0) {
                mContentView.setTranslationY(0);
                translationViewPager();
                mLastY = y;
                return super.onTouchEvent(event);
            }

            //向上滑动,并且contentView已经平移到最大距离,则contentView平移到最大的距离
            if (dy < 0 && mContentView.getTranslationY() + dy <= -mContentViewTranslateY) {
                mContentView.setTranslationY(-mContentViewTranslateY);
                translationViewPager();
                mLastY = y;
                return super.onTouchEvent(event);
            }
            //否则按比例平移
            mContentView.setTranslationY(mContentView.getTranslationY() + dy);
            translationViewPager();
            mLastY = y;
            break;

在ACTION_MOVE case 中有逻辑重新分发了事件,调用了 dispatchTouchEvent(event), 将action替换成了ACTION_DOWN;

如果此时刚好也手指抬起,下一个事件是 ACTION_UP,而且 X,Y 和这一次 ACTION_MOVE 的 X,Y接近,满足触发点击的要求

mContentView 就会触发点击事件(比如RecyclerView的Item就会被点击)

此问题是在滑动过程中刚好卡在这个点上。

@purezh521
Copy link

我也遇到这个问题了,请问您最后解决了吗?

@xiaojianli
Copy link
Author

我也遇到这个问题了,请问您最后解决了吗?
么得解决,规避了下
在CalendarView#setOnViewChangeListener 的回调中记了一个时间标记,在列表Item的点击处理时判断了当前时间和之前这个时间标记的差值是否小于某个阈值,小于就没处理这次点击。阈值150左右,基本也没再复现到。

@purezh521
Copy link

好的 谢谢 我试试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants