Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix strange space at the top when FlexWrap (#522) #530

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not a correct way to fix the issue.

Actually some of the tests in FlexboxLayoutMangerTests are failing after patching this PR.

Couldn't look into the issue carefully, but I guess what needs to be cared is not whether the main axis direction is horizontal, but whether the flex wrap is nowrap.

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