question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable scroll but allow tap on item

See original GitHub issue

@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: https://github.com/kizitonwose/CalendarView/issues/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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
kizitonwosecommented, Sep 1, 2019

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

2reactions
kizitonwosecommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevent body scrolling but allow overlay scrolling
I attempted to create this with just CSS (i.e. a div overlay on top of the whole page and body with overflow: hidden...
Read more >
Disable scroll but allow tap on item #38
The problem is that by disabling the scroll I'm intercepting the Action.MOVE used by the taps as well, therefore onInterceptTouchEvent is ...
Read more >
Prevent Scroll On Scrollable Elements [JS & CSS]
Need to temporally disable scrolling on a specifc scrollable element? Here are 5 ways to do it!
Read more >
How to disable scrolling temporarily using JavaScript
To enable the scrolling back, window.onscroll is overridden with a blank function. This will enable the scrolling of the page again.
Read more >
Prevent Scroll Chaining With Overscroll Behavior
How to prevent scroll chaining with overscroll-behavior property in CSS.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found