Smarter position provided by getPopupText(position)
See original GitHub issueActual Behavior
I implemented in my app a fullscreen RecyclerView with getPopupText
support. It looks like this:
The problem is, the position provided by
getPopupText
is the first visible item in the Adapter. Though as you can see here, this item (framed in red) is actually barely visible. So while the user only sees items starting with “L”, the popup still shows “K”, because the very last “K” item still hasn’t been recycled.
I was thinking maybe there is a smarter way than getFirstItemAdapterPosition()
to get this position.
As I’m a bit curious, I investigated how other fast scrollers handle this issue. For instance, Nova Launcher’s widget list uses a fast scroll which applies some kind of padding to this position, proportional to how low you are in the list (the more you scroll, the lower the item targeted by getPopupText
is on the screen). Which enables their popup to use the very first item’s position when you’re at the top, the very last item’s position when you’re at the bottom, and the position of an item which is always visible when you’re anywhere in between.
It’s kinda hard to explain with words. Actually experimenting with it helps to understand. I am also aware that the Google Contacts app works in a similar way (using the first visible item), though it’s not a problem because their list is not full screen, and the list snaps when fast scrolling, to make sure the first item is always fully visible. Not all lists can mimic this behavior though.
Expected Behavior
The position provided by getPopupText
should target an item which is always (clearly) visible to the user.
Steps to Reproduce the Problem
- Create a
RecyclerView
and simply bind a FastScroller withFastScrollerBuilder(recyclerView).build()
(the issue is more visible with a full screen RV). - Implement
PopupTextProvider
in the Adapter. - Scroll.
Specifications
- Version: v1.1.0
- Platform: Android 10, OnePlus 6 OxygenOS 10.3.1, no root
Don’t hesitate to ask for more details if it wasn’t clear. 😃 Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (2 by maintainers)
Hi. I am using the following code to improve the accuracy of obtaining the popup text.
@zhanghai Wouldn’t it be better to replace the implementation of
RecyclerViewHelper.getFirstItemAdapterPosition
by something that usesLinearLayoutManager
’sFindXXXVisibleItemPosition
instead of fetching the first visible view of the layout and then computing its position ?This way it would be possible to give the user/developer control over which method to use between :
findFirstVisibleItemPosition
(= more or less what the current implementation does)findFirstCompletelyVisibleItemPosition
(= what the OP seems to want)findLastVisibleItemPosition
findLastCompletelyVisibleItemPosition