Skip to content

Commit

Permalink
fix(android): waterfall scrolling error with small content height
Browse files Browse the repository at this point in the history
  • Loading branch information
iPel authored and zealotchen0 committed May 25, 2023
1 parent 7770385 commit 36ea10d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,42 +121,24 @@ public int getHeaderHeight(int index) {
int[] calculateColumnHeightsBefore(int position, boolean caculateOffsetmap) {
// #lizard forgives
int[] columnHeights = new int[mColumns];
SparseArray<List<Integer>> items = new SparseArray<>();
int n = 0;
// SparseArray<List<Integer>> items = new SparseArray<>();

HippyWaterfallAdapter adapter = (HippyWaterfallAdapter) mRecyclerView.getAdapter();

if (mHasContainBannerView) {
position += 1;
}

for (int i = 0; i < position; i++) {
int targetColumnIndex = 0;
for (int j = 0; j < columnHeights.length; j++) {
if (columnHeights[targetColumnIndex] > columnHeights[j]) {
targetColumnIndex = j;
}
}
int myHeight = adapter.getItemHeight(i) + adapter.getItemMaigin(RecyclerAdapter.LOCATION_TOP, i)
+ adapter.getItemMaigin(RecyclerAdapter.LOCATION_BOTTOM, i);

if (mHasContainBannerView) {
if (i == 0 || i == 1) {
n = 0;
} else if (i > 1) {
n = i - 1;
}
} else {
n = i;
if (i == 0 && mHasContainBannerView) {
Arrays.fill(columnHeights, myHeight);
continue;
}

int myHeight = adapter.getItemHeight(n) + adapter
.getItemMaigin(RecyclerAdapter.LOCATION_TOP, n)
+ adapter.getItemMaigin(RecyclerAdapter.LOCATION_BOTTOM, n);

RenderNode node = adapter.getItemNode(i);
if (node instanceof PullFooterRenderNode) {
int height = getHightestColumnHeight(columnHeights) + myHeight;
Arrays.fill(columnHeights, height);
} else {
int targetColumnIndex = getShortestColumnIndex(columnHeights);
columnHeights[targetColumnIndex] += myHeight;
}
}
Expand All @@ -166,51 +148,12 @@ int[] calculateColumnHeightsBefore(int position, boolean caculateOffsetmap) {
// calculate the height of every column after the item with index position.
public int[] calculateColumnHeightsAfter(int position) {
// #lizard forgives
int[] columnHeights = new int[mColumns];
SparseArray<List<Integer>> items = new SparseArray<>();
int n = 0;
HippyWaterfallAdapter adapter = (HippyWaterfallAdapter) mRecyclerView.getAdapter();

if (mHasContainBannerView) {
position += 1;
}

for (int i = 0; i <= position; i++) {
int targetColumnIndex = 0;
for (int j = 0; j < columnHeights.length; j++) {
if (columnHeights[targetColumnIndex] > columnHeights[j]) {
targetColumnIndex = j;
}
}

if (mHasContainBannerView) {
if (i == 0 || i == 1) {
n = 0;
} else if (i > 1) {
n = i - 1;
}
} else {
n = i;
}

int myHeight = adapter.getItemHeight(n) + adapter
.getItemMaigin(RecyclerAdapter.LOCATION_TOP, n)
+ adapter.getItemMaigin(RecyclerAdapter.LOCATION_BOTTOM, n);

RenderNode node = adapter.getItemNode(i);
if (node instanceof PullFooterRenderNode) {
int height = getHightestColumnHeight(columnHeights) + myHeight;
Arrays.fill(columnHeights, height);
} else {
columnHeights[targetColumnIndex] += myHeight;
}
}
return columnHeights;
return calculateColumnHeightsBefore(position + 1, false);
}

public static int getShortestColumnIndex(int[] columnHeights) {
int shortestColumnIndex = 0;
for (int j = 0; j < columnHeights.length; ++j) {
for (int j = 1; j < columnHeights.length; ++j) {
if (columnHeights[shortestColumnIndex] > columnHeights[j]) {
shortestColumnIndex = j;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/* Tencent is pleased to support the open source community by making Hippy available.
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.tencent.mtt.supportui.views.recyclerview;

import java.util.ArrayList;
Expand Down Expand Up @@ -1257,19 +1272,21 @@ private int scrollBy(int dy, RecyclerViewBase.Recycler recycler, RecyclerViewBas
// }
// ensureSuspensionState(layoutDirection);
updateRenderState(layoutDirection, absDy, true, state);
final int freeScroll = mRenderState.mScrollingOffset;
//final int freeScroll = mRenderState.mScrollingOffset;
//Log.e("RecyclerView", "start scroll---------------------dy=" + dy);
final int consumed = freeScroll + fill(recycler, mRenderState, state, false);
if (consumed < 0)
{
if (DEBUG)
{
//final int consumed = freeScroll + fill(recycler, mRenderState, state, false);
fill(recycler, mRenderState, state, false);
//if (consumed < 0)
//{
// if (DEBUG)
// {
// Log.d(TAG, "Don't have any more elements to scroll");
}
return 0;
// }
// return 0;

}
final int scrolled = absDy > consumed ? layoutDirection * consumed : dy;
//}
//final int scrolled = absDy > consumed ? layoutDirection * consumed : dy;
final int scrolled = dy;
mOrientationHelper.offsetChildren(-scrolled);
if (DEBUG)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/* Tencent is pleased to support the open source community by making Hippy available.
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.tencent.mtt.supportui.views.recyclerview;

import static com.tencent.mtt.supportui.views.recyclerview.RecyclerViewItem.ITEM_VIEW_DEFAULT_HEIGHT;
Expand Down Expand Up @@ -1044,10 +1059,10 @@ public View getFooterView(int position)
}
}

public int getDefaultFooterHeight()
{
return 108;
}
// public int getDefaultFooterHeight()
// {
// return 108;
// }

// 用户上拉触发了加载,footer开始转圈,业务开始拉去数据
@Override
Expand Down

0 comments on commit 36ea10d

Please sign in to comment.