rubensousa / GravitySnapHelper

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

Find out which item was snapped? #8

Closed manabreak closed 8 years ago

manabreak commented 8 years ago

I'm trying to do a snappy recycler view and your code works perfectly for that. However, I'm trying to figure out how to get the index of the item that was snapped. I proxied the findTargetSnapPosition method, but it tends to return -1 quite often.

Any idea how to fetch the position, preferably by listening to the snap helper?

rubensousa commented 8 years ago

Do you want to listen to the snap event or just query the snapped item? If it's the first one, there's no support for this yet, but might be interesting to add. If it's the last one, you can use findFirstCompletelyVisibleItemPosition/findLastCompletelyVisibleItemPosition from LinearLayoutManager.

manabreak commented 8 years ago

I'm interested in the former one - listening to the snaps. I did manage to use a addOnScrollListener() and listening for the state changes. More precisely: When the state is SCROLL_STATE_IDLE, I check whether the layout.findFirstCompletelyVisibleItemPosition() is greater than -1. If it is, we have a bound item.

rubensousa commented 8 years ago

So did you manage to do it?

manabreak commented 8 years ago

Yes, using the method I mentioned above. Although it could be a nice addition to implement in the helper itself.

rubensousa commented 8 years ago

Added in https://github.com/rubensousa/RecyclerViewSnap/commit/7e0e1687e8322bd232e53e2c04861ca286eb24b7.

Will be out in 1.0, after google releases the fix for: https://code.google.com/p/android/issues/detail?id=223649

rubensousa commented 8 years ago

1.0 released :)