Skip to content

Commit

Permalink
Fixed #116 - Header translation when child has height/width < height/…
Browse files Browse the repository at this point in the history
…width of it's header
  • Loading branch information
zoopolitic authored and davideas committed Jun 18, 2016
1 parent dd96c16 commit 6c35a4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ public List<IHeader> getHeaderItems() {
return headers;
}

public boolean isHeader(@NonNull T item) {
public boolean isHeader(T item) {
return item != null && item instanceof IHeader;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,14 @@ private void translateHeader() {
nextChildHeaderPosition = ((StaggeredGridLayoutManager) mRecyclerView.getLayoutManager()).getSpanCount();
}
//Search for the position where the next header item is found and take the new offset
for (int i = nextChildHeaderPosition; i > 0; i--) {
final View nextChild = mRecyclerView.getChildAt(i);
for (int i = 0; i < mRecyclerView.getChildCount(); i++) {
final View nextChild = mRecyclerView.getChildAt(i);
if (nextChild != null) {
int adapterPos = mRecyclerView.getChildAdapterPosition(nextChild);
//noinspection unchecked
if (!mAdapter.isHeader(mAdapter.getItem(adapterPos)) && childIsSmallerThanHeader(nextChild)) {
continue;
}
int nextHeaderPosition = getHeaderPosition(adapterPos);
if (mHeaderPosition != nextHeaderPosition) {
if (getOrientation(mRecyclerView) == OrientationHelper.HORIZONTAL) {
Expand All @@ -205,6 +209,13 @@ private void translateHeader() {
//Log.v(TAG, "TranslationX=" + headerOffsetX + " TranslationY=" + headerOffsetY);
}

private boolean childIsSmallerThanHeader(View nextChild) {
if (getOrientation(mRecyclerView) == OrientationHelper.HORIZONTAL) {
return nextChild.getWidth() < mStickyHeaderViewHolder.itemView.getWidth();
}
return nextChild.getHeight() < mStickyHeaderViewHolder.itemView.getHeight();
}

private void swapHeader(FlexibleViewHolder newHeader) {
if (mStickyHeaderViewHolder != null) {
resetHeader(mStickyHeaderViewHolder);
Expand Down

0 comments on commit 6c35a4d

Please sign in to comment.