Android-SnappingRecyclerView icon indicating copy to clipboard operation
Android-SnappingRecyclerView copied to clipboard

OnClick only allowed for centered item

Open patrickmuhi opened this issue 7 years ago • 1 comments

Add onClick support for child items too

patrickmuhi avatar Jun 17 '17 12:06 patrickmuhi

You should replace dispatchTouchEvent(MotionEvent event) with this and it will work :)

    `   @Override
public boolean dispatchTouchEvent(MotionEvent event) {
    long currentTime = System.currentTimeMillis();

    /* if touch events are being spammed, this is due to user scrolling right after a tap,
     * so set userScrolling to true **/
    if (_scrolling && _scrollState == SCROLL_STATE_TOUCH_SCROLL) {
        if ((currentTime - _lastScrollTime) < MINIMUM_SCROLL_EVENT_OFFSET_MS) {
            _userScrolling = true;
        }
    }

    _lastScrollTime = currentTime;

    int location = _orientation == Orientation.VERTICAL ? (int) event.getY() : (int) event.getX();

    View targetView = getChildClosestToLocation(location);

    if (!_userScrolling) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
            if (targetView != getCenterView() && targetView != null) {
                //scrollToView(targetView);
                targetView.performClick();
                return true;
            }
        }
    }

    return super.dispatchTouchEvent(event);
}

`

NaqiControl avatar Aug 18 '20 14:08 NaqiControl