ScrollView bounces back on some android devices, when ScrollVIew set horizontal is true。
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 127k
- Forks
- 25.3k
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 4
Description
Description
Vertical scrolling, Android has made special adjustments to the P version, but horizontal scrolling has not been addressed, resulting in rebound issues when horizontal scrolling is too fast. The following is the processing code for vertical scrolling and the code for not processing the Android P version during horizontal scrolling.
vertical scrollview
@Override
public void fling(int velocityY) {
final int correctedVelocityY = correctFlingVelocityY(velocityY);
if (mPagingEnabled) {
flingAndSnap(correctedVelocityY);
} else if (mScroller != null) {
// FB SCROLLVIEW CHANGE
// We provide our own version of fling that uses a different call to the standard OverScroller
// which takes into account the possibility of adding new content while the ScrollView is
// animating. Because we give essentially no max Y for the fling, the fling will continue as
// long
// as there is content. See #onOverScrolled() to see the second part of this change which
// properly
// aborts the scroller animation when we get to the bottom of the ScrollView content.
int scrollWindowHeight = getHeight() - getPaddingBottom() - getPaddingTop();
mScroller.fling(
getScrollX(), // startX
getScrollY(), // startY
0, // velocityX
correctedVelocityY, // velocityY
0, // minX
0, // maxX
0, // minY
Integer.MAX_VALUE, // maxY
0, // overX
scrollWindowHeight / 2 // overY
);
ViewCompat.postInvalidateOnAnimation(this);
// END FB SCROLLVIEW CHANGE
} else {
super.fling(correctedVelocityY);
}
handlePostTouchScrolling(0, correctedVelocityY);
}
private int correctFlingVelocityY(int velocityY) {
if (Build.VERSION.SDK_INT != Build.VERSION_CODES.P) {
return velocityY;
}
// Workaround.
// On Android P if a ScrollView is inverted, we will get a wrong sign for
// velocityY (see https://issuetracker.google.com/issues/112385925).
// At the same time, mOnScrollDispatchHelper tracks the correct velocity direction.
//
// Hence, we can use the absolute value from whatever the OS gives
// us and use the sign of what mOnScrollDispatchHelper has tracked.
float signum = Math.signum(mOnScrollDispatchHelper.getYFlingVelocity());
if (signum == 0) {
signum = Math.signum(velocityY);
}
return (int) (Math.abs(velocityY) * signum);
}
horizontal scrollview
@Override
public void fling(int velocityX) {
if (DEBUG_MODE) {
FLog.i(TAG, "fling[%d] velocityX %d", getId(), velocityX);
}
// Workaround.
// On Android P if a ScrollView is inverted, we will get a wrong sign for
// velocityX (see https://issuetracker.google.com/issues/112385925).
// At the same time, mOnScrollDispatchHelper tracks the correct velocity direction.
//
// Hence, we can use the absolute value from whatever the OS gives
// us and use the sign of what mOnScrollDispatchHelper has tracked.
final int correctedVelocityX =
(int) (Math.abs(velocityX) * Math.signum(mOnScrollDispatchHelper.getXFlingVelocity()));
if (mPagingEnabled) {
flingAndSnap(correctedVelocityX);
} else if (mScroller != null) {
// FB SCROLLVIEW CHANGE
// We provide our own version of fling that uses a different call to the standard OverScroller
// which takes into account the possibility of adding new content while the ScrollView is
// animating. Because we give essentially no max X for the fling, the fling will continue as
// long
// as there is content. See #onOverScrolled() to see the second part of this change which
// properly
// aborts the scroller animation when we get to the bottom of the ScrollView content.
int scrollWindowWidth =
getWidth() - ViewCompat.getPaddingStart(this) - ViewCompat.getPaddingEnd(this);
mScroller.fling(
getScrollX(), // startX
getScrollY(), // startY
correctedVelocityX, // velocityX
0, // velocityY
0, // minX
Integer.MAX_VALUE, // maxX
0, // minY
0, // maxY
scrollWindowWidth / 2, // overX
0 // overY
);
ViewCompat.postInvalidateOnAnimation(this);
// END FB SCROLLVIEW CHANGE
} else {
super.fling(correctedVelocityX);
}
handlePostTouchScrolling(correctedVelocityX, 0);
}
React Native Version
0.71.4
Output of npx react-native info
System:
OS: macOS 13.2
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 19.23 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.14.0 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 8.3.1 - /usr/local/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.10.1 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: 2022.1 AI-221.6008.13.2211.9514443
Xcode: 14.2/14C18 - /usr/bin/xcodebuild
Languages:
Java: 19.0.1 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.4 => 0.71.4
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
Set scrollview to horizontal scrolling, then fill in sub elements to allow scrollview to scroll horizontally, and then continuously slide towards the bottom when scrollview scrolls to the bottom, causing scrollview to experience rebound issues.
Snack, code example, screenshot, or link to a repository
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the Android horizontal ScrollView fling(int velocityX) path shown in the issue, comparing it with the vertical fling implementation and the Android P workaround. Reproduce the rapid horizontal swipe at the end of scrollable content on an affected Android device; done means the ScrollView no longer rebounds while normal horizontal fling behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java, react-native
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100