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

disable momentum scrolling for vertical ScrollView #27666

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ export type Props = $ReadOnly<{|
/**
* When true, the scroll view stops on the next index (in relation to scroll
* position at release) regardless of how fast the gesture is. This can be
* used for horizontal pagination when the page is less than the width of
* the ScrollView. The default value is false.
* used for pagination when the page is less than the width of the
* horizontal ScrollView or the height of the vertical ScrollView. The default value is false.
*/
disableIntervalMomentum?: ?boolean,
/**
Expand Down
2 changes: 2 additions & 0 deletions React/Views/ScrollView/RCTScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
if (isHorizontal) {
// Use current scroll offset to determine the next index to snap to when momentum disabled
targetContentOffsetAlongAxis = self.disableIntervalMomentum ? scrollView.contentOffset.x : targetContentOffset->x;
} else {
targetContentOffsetAlongAxis = self.disableIntervalMomentum ? scrollView.contentOffset.y : targetContentOffset->y;
}

// Offset based on desired alignment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class ReactScrollView extends ScrollView
private @Nullable String mScrollPerfTag;
private @Nullable Drawable mEndBackground;
private int mEndFillColor = Color.TRANSPARENT;
private boolean mDisableIntervalMomentum = false;
private int mSnapInterval = 0;
private float mDecelerationRate = 0.985f;
private @Nullable List<Integer> mSnapOffsets;
Expand Down Expand Up @@ -135,6 +136,10 @@ private OverScroller getOverScrollerFromParent() {
return scroller;
}

public void setDisableIntervalMomentum(boolean disableIntervalMomentum) {
mDisableIntervalMomentum = disableIntervalMomentum;
}

public void setSendMomentumEvents(boolean sendMomentumEvents) {
mSendMomentumEvents = sendMomentumEvents;
}
Expand Down Expand Up @@ -609,6 +614,10 @@ private void flingAndSnap(int velocityY) {

int maximumOffset = getMaxScrollY();
int targetOffset = predictFinalScrollPosition(velocityY);
if (mDisableIntervalMomentum) {
targetOffset = getScrollY();
}

int smallerOffset = 0;
int largerOffset = maximumOffset;
int firstOffset = 0;
Expand Down