How can i check if the recycler view is scrolled to its top (the begin of list) without using findFirstCompletelyVisibleItemPosition
?
Explanation: I cant use this method, because the items on RecyclerView
are big and sometimes will never be "completely visible", so the method will return -1 (RecyclerView.NO_POSITION
)
I need to know this to fire an action only when recycler view reach its top.
val manager = timelineRecyclerView?.layoutManager as StaggeredGridLayoutManager
val visibles = manager.findFirstCompletelyVisibleItemPositions(null)
Solved: Including some code to help
timelineRecyclerView.addOnScrollListener(object:RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView:RecyclerView,
newState:Int) {
super.onScrollStateChanged(recyclerView, newState)
}
override fun onScrolled(recyclerView:RecyclerView, dx:Int, dy:Int) {
super.onScrolled(recyclerView, dx, dy)
currentTimelinePosition += dy
Log.wtf("position", currentTimelinePosition.toString())
//if the timeline position is on its start, allow swipe and refresh
swipeLayout.isEnabled = currentTimelinePosition == 0
}
})