ScrollView bounces back on some android devices, when ScrollVIew set horizontal is true。
Nessuno ha ancora preso questa issue.
- Lingua principale
- C++
- Stelle
- 127k
- Fork
- 25.3k
- Merge medio
- 1g 23h
- PR unite (30g)
- 4
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Esamina il percorso di Android ScrollView fling(int velocityX) mostrato nell’issue, confrontandolo con l’implementazione verticale di fling e il workaround di Android P. Riproduci lo swipe orizzontale rapido alla fine del contenuto scorrevole su un dispositivo Android interessato; il lavoro è completato quando ScrollView non rimbalza più, mentre il normale comportamento del fling orizzontale rimane intatto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- android, java, react-native
- Ambito
- mobile
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100