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

Can't scroll on RecyclerView when the item has click listener #160

Open
wendrawang opened this issue Aug 14, 2020 · 9 comments
Open

Can't scroll on RecyclerView when the item has click listener #160

wendrawang opened this issue Aug 14, 2020 · 9 comments

Comments

@wendrawang
Copy link

I cant scroll the specific item in RecyclerView if that item has click listener.

@wendrawang wendrawang changed the title Can't scroll Can't scroll on RecyclerView when the item has click listener Aug 14, 2020
@alexvasilkov
Copy link
Owner

Too little details, please provide a proper description with examples and explanation how RecyclerView items issue is related to this library.

@wendrawang
Copy link
Author

I'm using like this :

<com.alexvasilkov.gestures.views.GestureFrameLayout
        android:id="@+id/moving_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycle_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
</com.alexvasilkov.gestures.views.GestureFrameLayout>

inside the recyclerview adapter, i have specific item that has onClickListener

val header = HeaderViewHolder(layoutView)
if(position == 1) {
      header.reloadBtn.setOnClickListener {}
}

i cant scroll the recycler from that inside specific item that has onclicklistener, but i can click on other item that doesnt has onclicklistener

video sample : (the item that cant scroll is the one that has onclicklistener)
sample

@alexvasilkov
Copy link
Owner

I tried adding RecyclerView with buttons into GestureFrameLayout and it seems to handle both clicks and scrolling (started on a button) just fine.

Note that there was a fix for nested scrolling in the latest version, do you use 2.6.0?

If you still have the issue in v2.6.0 then I'll need exact code (e.g. a sample project) to reproduce it.

@luthfi-ali
Copy link

I had the same issue too, using version 2.7.1

@alexvasilkov
Copy link
Owner

Can you reproduce the issue in the sample app? Or can you modify the sample app in the way that will showcase this issue?
I tried it myself and wasn't able to reproduce it, but without understanding what exactly is not working for you I can do little.

@luthfi-ali
Copy link

luthfi-ali commented Dec 17, 2020

This is my case

I just load a list of simple ImageView with RecyclerView, and I set a click listener to the ImageView and I can't even scroll the list.
When I removed the click listener it scrolled just fine. My workaround is to set the click listener to GestureFrameLayout instead of ImageView as I have the same logic for all clicks without needing the image data anyway.

@luthfi-ali
Copy link

This is my code, maybe it could help. As I haven't had the time to look at the example.

Activity

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/refresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.alexvasilkov.gestures.views.GestureFrameLayout
        android:id="@+id/zoom_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:listitem="@layout/item_comic_chapter_read" />

    </com.alexvasilkov.gestures.views.GestureFrameLayout>

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

item layout
<ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/image_iv" android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="fitCenter" />

View holder
`
public class ChapterReadViewHolder extends RecyclerView.ViewHolder {
private final ImageView ivImage;

public ChapterReadViewHolder(View view) {
    super(view);

    ivImage = view.findViewById(R.id.image_iv);
}

public void bindData(ChapterPage data) {
    Glide.with(ivImage)
            .load(data.getImagePath())
            .into(ivImage);
    
    ivImage.setOnClickListener(v -> Log.d("Test", "Hello"));
}

}
`

It's just a simple list actually.

@alexvasilkov
Copy link
Owner

Yes, thanks, I can reproduce it now, not sure why I didn't see that myself.

I did a quick research and it turns out that if RecyclerView items are clickable then RecyclerView will call requestDisallowInterceptTouchEvent() much later and by that time GestureFrameLayout will already accumulate enough touch scroll to decide to take control over all the touch events.

Nested scrolling is complicated, Google added a lot of logic accross their widgets in the last several years to support it, but before that it wasn't really possible to nest widgets that can scroll in same direction.

The solution now is to partly rewrite this library to implement all the APIs provided by Google to have a smooth nesting scroll. But that is a hell lot of work, so I doubt I will had a time to do that anytime soon.

BTW, can you explain why do you need to nest RecyclerView inside the GestureFrameLayout, what is your use case?

@luthfi-ali
Copy link

Hi, thanks for the reply and the research.

I'm building a comic reader app. It's just a list of images but it also needs to be zoomable. I tried it with zoomable feature per ImageView but the user experience looks weird, so I looked at another comic app (ex webtoon) and they were zoomable as a whole. So I'm thinking that it should be the RecyclerView that was zoomed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants