Skip to content

Commit

Permalink
Merge pull request #126 from AlanCheen/bugfix/isglm
Browse files Browse the repository at this point in the history
Bugfix/isglm
  • Loading branch information
AlanCheen authored Nov 1, 2022
2 parents 7b06010 + 8741a0d commit 2b690dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,15 @@ boolean checkForGaps() {

@Override
public void onScrollStateChanged(int state) {
if (state == RecyclerView.SCROLL_STATE_IDLE) {
checkForGaps();
if (reLayoutOnScrollToTop) {
handleAutoReLayoutWhenScrollToTop();
try {
if (state == RecyclerView.SCROLL_STATE_IDLE) {
checkForGaps();
if (reLayoutOnScrollToTop) {
handleAutoReLayoutWhenScrollToTop();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

Expand Down Expand Up @@ -2544,6 +2548,14 @@ int getStartLine(int def) {
}

void calculateCachedStart() {
// Fatal Exception: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
// https://stackoverflow.com/questions/44571895/staggeredgridlayoutmanager-calculatecachedstart-indexoutofboundsexception
// 解法: 设置 mGapStrategy == GAP_HANDLING_NONE
// 这里主动规避一下 IndexOutOfBoundsException
if (mViews.size() == 0) {
return;
}

final View startView = mViews.get(0);
final FlapIndexedStaggeredGridLayoutManager.LayoutParams lp = getLayoutParams(startView);
mCachedStart = mPrimaryOrientation.getDecoratedStart(startView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ open class FlapStaggeredGridLayoutManager
FlapDebug.e(TAG, "onLayoutChildren: ", e)
}
}

override fun onScrollStateChanged(state: Int) {
try {
super.onScrollStateChanged(state)
} catch (e: Exception) {
e.printStackTrace()
FlapDebug.e(TAG, "onScrollStateChanged: ", e)
}
}
}

0 comments on commit 2b690dc

Please sign in to comment.