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

Add option to disable calculateScrollForSelectingPosition() function #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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 @@ -52,6 +52,7 @@ public class CarouselLayoutManager extends RecyclerView.LayoutManager implements

private final int mOrientation;
private final boolean mCircleLayout;
private final boolean mCalculateScroll;

private int mPendingScrollPosition;

Expand All @@ -71,7 +72,7 @@ public class CarouselLayoutManager extends RecyclerView.LayoutManager implements
*/
@SuppressWarnings("unused")
public CarouselLayoutManager(final int orientation) {
this(orientation, CIRCLE_LAYOUT);
this(orientation, CIRCLE_LAYOUT, true);
}

/**
Expand All @@ -82,11 +83,21 @@ public CarouselLayoutManager(final int orientation) {
*/
@SuppressWarnings("unused")
public CarouselLayoutManager(final int orientation, final boolean circleLayout) {
this(orientation, circleLayout, true);
}

/**
* @param orientation should be {@link #VERTICAL} or {@link #HORIZONTAL}
* @param circleLayout true for enabling circleLayout
* @param calculateScroll whether {@link CarouselLayoutManager#calculateScrollForSelectingPosition(int, RecyclerView.State)} should be called in {@link CarouselLayoutManager#onLayoutChildren(RecyclerView.Recycler, RecyclerView.State)}
*/
public CarouselLayoutManager(final int orientation, final boolean circleLayout, final boolean calculateScroll) {
if (HORIZONTAL != orientation && VERTICAL != orientation) {
throw new IllegalArgumentException("orientation should be HORIZONTAL or VERTICAL");
}
mOrientation = orientation;
mCircleLayout = circleLayout;
mCalculateScroll = calculateScroll;
mPendingScrollPosition = INVALID_POSITION;
}

Expand Down Expand Up @@ -358,14 +369,20 @@ public void onLayoutChildren(@NonNull final RecyclerView.Recycler recycler, @Non
mPendingScrollPosition = 0 == itemsCount ? INVALID_POSITION : Math.max(0, Math.min(itemsCount - 1, mPendingScrollPosition));
}
if (INVALID_POSITION != mPendingScrollPosition) {
mLayoutHelper.mScrollOffset = calculateScrollForSelectingPosition(mPendingScrollPosition, state);
if (mCalculateScroll) {
mLayoutHelper.mScrollOffset = calculateScrollForSelectingPosition(mPendingScrollPosition, state);
}
mPendingScrollPosition = INVALID_POSITION;
mPendingCarouselSavedState = null;
} else if (null != mPendingCarouselSavedState) {
mLayoutHelper.mScrollOffset = calculateScrollForSelectingPosition(mPendingCarouselSavedState.mCenterItemPosition, state);
if (mCalculateScroll) {
mLayoutHelper.mScrollOffset = calculateScrollForSelectingPosition(mPendingCarouselSavedState.mCenterItemPosition, state);
}
mPendingCarouselSavedState = null;
} else if (state.didStructureChange() && INVALID_POSITION != mCenterItemPosition) {
mLayoutHelper.mScrollOffset = calculateScrollForSelectingPosition(mCenterItemPosition, state);
if (mCalculateScroll) {
mLayoutHelper.mScrollOffset = calculateScrollForSelectingPosition(mCenterItemPosition, state);
}
}

fillData(recycler, state, childMeasuringNeeded);
Expand Down