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

Is there a way to hide the handle when the list is not being scrolled? #130

Open
nicoqueijo opened this issue Apr 23, 2020 · 1 comment
Open

Comments

@nicoqueijo
Copy link

nicoqueijo commented Apr 23, 2020

When list is not in motion hide the handle. When list comes back to motion show the handle but in a fading manner.

@turing-tech
Copy link
Owner

turing-tech commented Dec 9, 2020

recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {

            val timer = Timer()
            var task: TimerTask? = null

            override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
                when (newState) {
                    RecyclerView.SCROLL_STATE_DRAGGING -> {
                        task?.cancel()
                        timer.purge()
                        task = null

                        if (binding.scrollBar.alpha != 1f) {
                            ObjectAnimator.ofFloat(binding.scrollBar.alpha, 1f).apply {
                                addUpdateListener { binding.scrollBar.alpha = it.animatedValue as Float }
                                duration = 250L * (1L - binding.scrollBar.alpha.toLong())
                                start()
                            }
                        }
                    }
                    RecyclerView.SCROLL_STATE_IDLE -> {
                        task = timerTask {
                            if (binding.scrollBar.isDragging) return@timerTask
                            activity?.runOnUiThread {
                                ObjectAnimator.ofFloat(1f, 0f).apply {
                                    addUpdateListener { binding.scrollBar.alpha = it.animatedValue as Float }
                                    duration = 250
                                    start()
                                }
                            }
                        }
                        timer.schedule(task, 500)
                    }
                }
            }
        })

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