rubensousa / GravitySnapHelper

A SnapHelper that snaps a RecyclerView to an edge.
Apache License 2.0
5k stars 614 forks source link

GravitySnapHelper.SnapListener not callback when scroll to first position. #64

Closed leeprohacker closed 4 years ago

leeprohacker commented 4 years ago

The issue when I set GravitySnapRecyclerView equal center and also set SnapListener for GravitySnapHelper. So the listener never callback "onSnap" when the recyclerview scrolled to top position and rest positions that working fine.

rubensousa commented 4 years ago

The top position won't be called in onSnap if it can't be snapped. This usually happens when you don't have padding or decoration for the top or bottom items.

leeprohacker commented 4 years ago

@rubensousa rube I looked into your example, in the row Center with decoration, it's same issue i mentioned above. In fact my project I have added decoration to make item center horizontal. So do you have any advices for me? Thanks

rubensousa commented 4 years ago

@leeprohacker I can confirm there's a problem. Sometimes the position 0 isn't dispatched on onSnap. I'll fix this in the next release

rubensousa commented 4 years ago

@leeprohacker it should be fixed in the develop branch now. Can you check if now it behaves like you would expect?

rubensousa commented 4 years ago

You can check this in your app by installing the version 2.2.1-beta01

rubensousa commented 4 years ago

Released on 2.2.1

Hoalq-0026 commented 3 years ago

@rubensousa Hi! I have a problem. I can not scroll to the top position when the call method smoothScrollToPosition(0) in source code:

ryclerviewTopic.apply {
                layoutManager = LinearLayoutManager(context)
               enableSnapping(false)
                adapter = topicAdapter
            }

ryclerviewTopic.smoothScrollToPosition(0)

 <com.github.rubensousa.gravitysnaphelper.GravitySnapRecyclerView
                        android:id="@+id/ryclerviewTopic"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_behavior="@string/appbar_scrolling_view_behavior"
                        app:snapEnabled="false"
                        app:snapGravity="top"
                        app:snapMaxFlingSizeFraction="2"
                        app:snapScrollMsPerInch="50"
                        android:paddingTop="@dimen/_30dp"
                        tools:listitem="@layout/item_home_topic" />