Skip to content

Commit

Permalink
fix strange space at the top when FlexWrap (google#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheckspir committed Jan 15, 2020
1 parent c641750 commit 168c1f4
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,14 @@ private boolean updateAnchorFromPendingState(RecyclerView.State state, AnchorInf
anchorInfo.mPosition = mPendingScrollPosition;
anchorInfo.mFlexLinePosition = mFlexboxHelper.mIndexToFlexLine[anchorInfo.mPosition];
if (mPendingSavedState != null && mPendingSavedState.hasValidAnchor(state.getItemCount())) {
anchorInfo.mCoordinate = mOrientationHelper.getStartAfterPadding() +
savedState.mAnchorOffset;
if (isMainAxisDirectionHorizontal()) {
anchorInfo.mCoordinate = mOrientationHelper.getLayoutManager().getPaddingTop() +
savedState.mAnchorOffset;
} else {
anchorInfo.mCoordinate = mOrientationHelper.getStartAfterPadding() +
savedState.mAnchorOffset;
}
Log.d("TAG","1updsteFromPendingState.mCoordinate = " + anchorInfo.mCoordinate);
anchorInfo.mAssignedFromSavedState = true;
anchorInfo.mFlexLinePosition = NO_POSITION;
return true;
Expand Down Expand Up @@ -1121,7 +1127,10 @@ private boolean updateAnchorFromPendingState(RecyclerView.State state, AnchorInf
}

// TODO: Support reverse layout when flex wrap == FlexWrap.WRAP_REVERSE
if (!isMainAxisDirectionHorizontal() && mIsRtl) {
if (isMainAxisDirectionHorizontal()) {
anchorInfo.mCoordinate = mOrientationHelper.getLayoutManager().getPaddingTop()
+ mPendingScrollPositionOffset;
} else if (mIsRtl) {
anchorInfo.mCoordinate = mPendingScrollPositionOffset
- mOrientationHelper.getEndPadding();
} else {
Expand Down Expand Up @@ -1445,9 +1454,7 @@ private int layoutFlexLineMainAxisHorizontal(FlexLine flexLine, LayoutState layo
int parentWidth = getWidth();

int childTop = layoutState.mOffset;
if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) {
childTop = childTop - flexLine.mCrossSize;
}

int startPosition = layoutState.mPosition;

float childLeft;
Expand Down Expand Up @@ -2878,7 +2885,10 @@ private void reset() {
}

private void assignCoordinateFromPadding() {
if (!isMainAxisDirectionHorizontal() && mIsRtl) {
if (isMainAxisDirectionHorizontal()) {
mCoordinate = mLayoutFromEnd? mOrientationHelper.getLayoutManager().getPaddingBottom()
: mOrientationHelper.getLayoutManager().getPaddingTop();
} else if (!isMainAxisDirectionHorizontal() && mIsRtl) {
mCoordinate = mLayoutFromEnd ? mOrientationHelper.getEndAfterPadding()
: getWidth() - mOrientationHelper.getStartAfterPadding();
} else {
Expand Down

0 comments on commit 168c1f4

Please sign in to comment.