Skip to content

Commit e666f96

Browse files
author
John Gray
committed
Added a check when searching for position of header, that the header found is visible.
1 parent cb962e8 commit e666f96

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

library/src/main/java/com/timehop/stickyheadersrecyclerview/StickyRecyclerHeadersAdapter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ public interface StickyRecyclerHeadersAdapter<VH extends RecyclerView.ViewHolder
3636
* @return the number of views in the adapter
3737
*/
3838
int getItemCount();
39+
40+
boolean isPositionVisible(final int position);
3941
}

library/src/main/java/com/timehop/stickyheadersrecyclerview/StickyRecyclerHeadersDecoration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ public int findHeaderPositionUnder(int x, int y) {
130130
for (int i = 0; i < mHeaderRects.size(); i++) {
131131
Rect rect = mHeaderRects.get(mHeaderRects.keyAt(i));
132132
if (rect.contains(x, y)) {
133-
return mHeaderRects.keyAt(i);
133+
int position = mHeaderRects.keyAt(i);
134+
if (mAdapter.isPositionVisible(position)) {
135+
return position;
136+
}
134137
}
135138
}
136139
return -1;

0 commit comments

Comments
 (0)