Skip to content

Commit 60c36a9

Browse files
committed
Making onPageChanged be called continuously
1 parent f20f30c commit 60c36a9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/src/main/java/com/lsjwzh/widget/recyclerviewpager/RecyclerViewPager.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class RecyclerViewPager extends RecyclerView {
4444
int mMinTopWhenDragging = Integer.MAX_VALUE;
4545
private int mPositionOnTouchDown = -1;
4646
private boolean mLoopEnabled;
47+
private boolean mHasCalledOnPageChanged = true;
4748

4849
public RecyclerViewPager(Context context) {
4950
this(context, null);
@@ -366,7 +367,11 @@ public void onScrollStateChanged(int state) {
366367
mCurView = getLayoutManager().canScrollHorizontally() ? ViewUtils.getCenterXChild(this) :
367368
ViewUtils.getCenterYChild(this);
368369
if (mCurView != null) {
369-
mPositionBeforeScroll = getChildLayoutPosition(mCurView);
370+
if (mHasCalledOnPageChanged) {
371+
// While rvp is scrolling, mPositionBeforeScroll will be previous value.
372+
mPositionBeforeScroll = getChildLayoutPosition(mCurView);
373+
mHasCalledOnPageChanged = false;
374+
}
370375
if (DEBUG) {
371376
Log.d("@", "mPositionBeforeScroll:" + mPositionBeforeScroll);
372377
}
@@ -424,6 +429,7 @@ public void onScrollStateChanged(int state) {
424429
}
425430
}
426431
}
432+
mHasCalledOnPageChanged = true;
427433
mPositionBeforeScroll = mSmoothScrollTargetPosition;
428434
}
429435
// reset

0 commit comments

Comments
 (0)