Skip to content

Commit 9413b24

Browse files
committed
Nested pre-fling for AbsListView and ScrollView
Add nested pre-fling support to all framework widgets that currently support nested fling. Change-Id: Ieaf9d12938dbfeea779c2aee2f5a081c287c8e96
1 parent 579befe commit 9413b24

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

core/java/android/widget/AbsListView.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3857,13 +3857,17 @@ public void run() {
38573857
firstChildTop == contentTop - mOverscrollDistance) ||
38583858
(mFirstPosition + childCount == mItemCount &&
38593859
lastChildBottom == contentBottom + mOverscrollDistance))) {
3860-
if (mFlingRunnable == null) {
3861-
mFlingRunnable = new FlingRunnable();
3860+
if (!dispatchNestedPreFling(0, -initialVelocity)) {
3861+
if (mFlingRunnable == null) {
3862+
mFlingRunnable = new FlingRunnable();
3863+
}
3864+
reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
3865+
mFlingRunnable.start(-initialVelocity);
3866+
dispatchNestedFling(0, -initialVelocity, true);
3867+
} else {
3868+
mTouchMode = TOUCH_MODE_REST;
3869+
reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
38623870
}
3863-
reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
3864-
3865-
mFlingRunnable.start(-initialVelocity);
3866-
dispatchNestedFling(0, -initialVelocity, true);
38673871
} else {
38683872
mTouchMode = TOUCH_MODE_REST;
38693873
reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
@@ -4029,7 +4033,9 @@ public boolean onNestedFling(View target, float velocityX, float velocityY, bool
40294033
if (mFlingRunnable == null) {
40304034
mFlingRunnable = new FlingRunnable();
40314035
}
4032-
mFlingRunnable.start((int) velocityY);
4036+
if (!dispatchNestedPreFling(0, velocityY)) {
4037+
mFlingRunnable.start((int) velocityY);
4038+
}
40334039
return true;
40344040
}
40354041
return dispatchNestedFling(velocityX, velocityY, consumed);

core/java/android/widget/ScrollView.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,9 +1577,11 @@ public void fling(int velocityY) {
15771577
private void flingWithNestedDispatch(int velocityY) {
15781578
final boolean canFling = (mScrollY > 0 || velocityY > 0) &&
15791579
(mScrollY < getScrollRange() || velocityY < 0);
1580-
dispatchNestedFling(0, velocityY, canFling);
1581-
if (canFling) {
1582-
fling(velocityY);
1580+
if (!dispatchNestedPreFling(0, velocityY)) {
1581+
dispatchNestedFling(0, velocityY, canFling);
1582+
if (canFling) {
1583+
fling(velocityY);
1584+
}
15831585
}
15841586
}
15851587

0 commit comments

Comments
 (0)