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

Nested Scrolling support #28

Open
awenger opened this issue Sep 1, 2016 · 3 comments
Open

Nested Scrolling support #28

awenger opened this issue Sep 1, 2016 · 3 comments

Comments

@awenger
Copy link

awenger commented Sep 1, 2016

I tried to use this library with a RecyclerView inside of a CoordinatorLayout that also contains a AppBarLayout with a Toolbar that uses app:layout_scrollFlags="scroll|enterAlways|snap":

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinator_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways|snap"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/store_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <com.futuremind.recyclerviewfastscroll.FastScroller
        android:id="@+id/fastscroll"
        android:orientation="vertical"
        android:layout_gravity="right"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_marginTop="?attr/actionBarSize"
        android:layout_marginBottom="?attr/actionBarSize"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</android.support.design.widget.CoordinatorLayout>

This has the following problems:

  • the FastScroller isn't collapsing/expanding the AppBarLayout
  • this prevents the FastScroller to scroll to the last entry in the list if the AppBarLayout is expanded
  • parts of the FastScroller are not visible (I quick fixed this problem with using marginTop/marginBottom for the FastScroller)

It seems that RecyclerView doesn't handle Nested Scrolling if you scroll with scrollToPosition. Sadly I couldn't find any proper documentation how Nested Scrolling is supposed to work. So I can't say if this is a bug in RecyclerView or this is supposed to be handled by the scroll initiator. But I think it is possible to handle it with:

  • ViewCompat.startNestedScroll
  • ViewCompat.dispatchNestedPreScroll
  • RecyclerView.scrollBy
  • ViewCompat.dispatchNestedScroll
  • ViewCompat.stopNestedScroll

This snippet demonstrates a way that let's the RecyclerView scroll by 300px while also collapsing the AppBarLayout. However I don't know this is the proper way to do it:

if (ViewCompat.isNestedScrollingEnabled(recyclerView) && ViewCompat.startNestedScroll(recyclerView, ViewCompat.SCROLL_AXIS_VERTICAL)) {
    int[] consumed = new int[2];
    ViewCompat.dispatchNestedPreScroll(recyclerView, 0, 300, consumed, null);
    int unsconumed = 300 - consumed[1];
    recyclerView.scrollBy(0, unsconumed);
    ViewCompat.dispatchNestedScroll(recyclerView, consumed[0], consumed[1], 0, unsconumed, null);
    ViewCompat.stopNestedScroll(recyclerView);
}

I'm not sure if it is possible to fix this problem with the current approach in this lib to scroll with scrollToPosition.

@micHar
Copy link
Contributor

micHar commented Sep 1, 2016

This is an interesting problem. I think that what you wrote about nested scrolling makes a perfect starting point. One should probably look into how RecyclerView handles various scroll methods internally and move to another method if scrollToPosition doesn't work as expected. Filing a RecyclerView bug in Google would tell us if this is intended or not. Anyway this has to be fixed. The problem is that I currently have no time for maintaining the lib, so if you wanted to contribute, investigate this issue and post a PR, that would be great.

@micHar
Copy link
Contributor

micHar commented Sep 1, 2016

Also, if you decide to file a bug to Google, reference it here, please.

@micHar micHar added bug and removed bug labels Sep 1, 2016
@awenger
Copy link
Author

awenger commented Sep 1, 2016

https://code.google.com/p/android/issues/detail?id=221455

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