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

Please support over scroll for NestedScrollView #45

Open
zappu9x opened this issue Aug 7, 2017 · 1 comment
Open

Please support over scroll for NestedScrollView #45

zappu9x opened this issue Aug 7, 2017 · 1 comment

Comments

@zappu9x
Copy link

zappu9x commented Aug 7, 2017

No description provided.

@Hafeezllah-Khan
Copy link

Hafeezllah-Khan commented Apr 13, 2023

Hi,

I have found a solution to add overscroll support for NestedScrollView using a custom adapter. Here's the code snippet for the custom adapter:

import android.view.View
import androidx.core.widget.NestedScrollView
import me.everything.android.ui.overscroll.adapters.IOverScrollDecoratorAdapter

class NestedScrollViewOverScrollDecorAdapter(private val mView: NestedScrollView) :
    IOverScrollDecoratorAdapter {

    override fun getView(): View {
        return mView
    }

    override fun isInAbsoluteStart(): Boolean {
        return !mView.canScrollVertically(-1)
    }

    override fun isInAbsoluteEnd(): Boolean {
        return !mView.canScrollVertically(1)
    }
}

Then, you can set up the overscroll effect in your Fragment or Activity like this:

val nestedScrollView = view.findViewById<NestedScrollView>(R.id.scroll)
val overScrollDecorAdapter = NestedScrollViewOverScrollDecorAdapter(nestedScrollView)
val overScrollDecorator = VerticalOverScrollBounceEffectDecorator(overScrollDecorAdapter)

overScrollDecorator.setOverScrollUpdateListener { _, _, offset ->
    val tension = 0.5f // Adjust the tension value here. Lower values result in less bounciness.
    val scaleFactor = 1f + tension * Math.abs(offset) / overScrollDecorAdapter.getView().height
    overScrollDecorAdapter.view.scaleY = scaleFactor.toFloat()
}

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