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

Disable scroll but allow tap on item #38

Closed
federicomiralles opened this issue Jul 30, 2019 · 7 comments
Closed

Disable scroll but allow tap on item #38

federicomiralles opened this issue Jul 30, 2019 · 7 comments

Comments

@federicomiralles
Copy link

federicomiralles commented Jul 30, 2019

@kizitonwose I'm stuck with the following situacion...
On one hand I need to disable the horizontal scrolling on the calendar as shown on here: #13 and do it programatically.
But at the same time I need to be able to tap/click on days of the calendar (by setting a click listener on the DayViewContainer view):
view.setOnClickListener(new View.OnClickListener()...
The problem is that by disabling the scroll I'm intercepting the Action.MOVE used by the taps as well, therefore onInterceptTouchEvent is swallowing the event, hence not allowing it to reach the defined view click listener.

So to sum up I need to disable the swiping of the calendar but allowing taps of each of days of the calendar...

Any suggestion?

Thanks in advance,

Federico

@kizitonwose
Copy link
Owner

Clicks are not detected using Action.MOVE event. I disabled scroll in example 5 in the sample app and clicks are still received. See the screen recording below:

Example 5

@federicomiralles
Copy link
Author

federicomiralles commented Jul 31, 2019

@kizitonwose I tried the same on my end by adding:

exFiveCalendar.addOnItemTouchListener(object : RecyclerView.SimpleOnItemTouchListener() {
            override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
                return if (e.action == MotionEvent.ACTION_MOVE) {
                    true
                } else {
                    super.onInterceptTouchEvent(rv, e)
                }
            }
        })

to the example you mentioned but I got the same result... I can't tap on a day...
I tried using a Motorola One with Android Pie.

@kizitonwose
Copy link
Owner

kizitonwose commented Jul 31, 2019

That's very strange. Can you test with a different phone?
Also, do you have any other click listeners attached on any other part of the calendar? Example, month header or footer?

Sadly, this is a problem with RecyclerView itself, not this library so I may not be able to help much.

@federicomiralles
Copy link
Author

@kizitonwose unfortunately it also happens on Samsung devices but it's strange because it does works on other like Xiaomi. :/

@kizitonwose
Copy link
Owner

Currently waiting to get a Samsung device to test with.

@kizitonwose
Copy link
Owner

kizitonwose commented Aug 28, 2019

I finally got my hands on a Samsung device and can confirm that the suggested workaround does not work on the device.

However, after further testing, there's another workaround which works on Samsung devices as well as other devices which I tested on:

calendarView.addOnItemTouchListener(object : RecyclerView.SimpleOnItemTouchListener() {
    override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
        return rv.scrollState == RecyclerView.SCROLL_STATE_DRAGGING
    }
})

For reference purposes, here are other things I tried and how they turned out.

calendarView.setOnTouchListener { _, event ->
    event.action == MotionEvent.ACTION_MOVE
}

The above workaround allows an initial scroll action on the calendar before taking effect which is rather weird.

Another option is to extend the CalenderView class and override the dispatchTouchEvent method.

override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
    return if (ev.action == MotionEvent.ACTION_MOVE) true else super.dispatchTouchEvent(ev)
}

This gives the desired result. However, while the calendar does not move after a swipe action, a touch event is registered at the start position of the swipe gesture, hence the date cell at that position receives a click event.

@kizitonwose
Copy link
Owner

Closing this issue as there's now a solution. If you need any further assistance, let me know.

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