Skip to content

Commit a9717cf

Browse files
yarakidsn5ft
authored andcommitted
Fix uses of deprecated API in BottomSheetBehavior
This fixes BottomSheetBehavior implementation and remove uses of deprecated APIs. The APIs are mainly about nested scrolling related to inertia scrolling by nested fling. This CL does not change the behavior. The inertia scrolling by nested fling is not enabled. For that, we will have to change the way we use ViewDragHelper, and let nested fling handle the inertia scrolling. Bug: 70912761 Test: Existing tests (BottomSheetBehaviorTest, BottomSheetDialogTest) Change-Id: Iaea50056ed253131c7920f703136d30e73918756 PiperOrigin-RevId: 183276945
1 parent 8f026e6 commit a9717cf

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

lib/java/android/support/design/widget/BottomSheetBehavior.java

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public void onRestoreInstanceState(CoordinatorLayout parent, V child, Parcelable
216216
@Override
217217
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
218218
if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) {
219-
ViewCompat.setFitsSystemWindows(child, true);
219+
child.setFitsSystemWindows(true);
220220
}
221221
int savedTop = child.getTop();
222222
// First let the parent lay it out
@@ -344,19 +344,30 @@ public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event
344344

345345
@Override
346346
public boolean onStartNestedScroll(
347-
CoordinatorLayout coordinatorLayout,
348-
V child,
349-
View directTargetChild,
350-
View target,
351-
int nestedScrollAxes) {
347+
@NonNull CoordinatorLayout coordinatorLayout,
348+
@NonNull V child,
349+
@NonNull View directTargetChild,
350+
@NonNull View target,
351+
int axes,
352+
int type) {
352353
lastNestedScrollDy = 0;
353354
nestedScrolled = false;
354-
return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
355+
return (axes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
355356
}
356357

357358
@Override
358359
public void onNestedPreScroll(
359-
CoordinatorLayout coordinatorLayout, V child, View target, int dx, int dy, int[] consumed) {
360+
@NonNull CoordinatorLayout coordinatorLayout,
361+
@NonNull V child,
362+
@NonNull View target,
363+
int dx,
364+
int dy,
365+
@NonNull int[] consumed,
366+
int type) {
367+
if (type == ViewCompat.TYPE_NON_TOUCH) {
368+
// Ignore fling here. The ViewDragHelper handles it.
369+
return;
370+
}
360371
View scrollingChild = nestedScrollingChildRef.get();
361372
if (target != scrollingChild) {
362373
return;
@@ -392,7 +403,11 @@ public void onNestedPreScroll(
392403
}
393404

394405
@Override
395-
public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, V child, View target) {
406+
public void onStopNestedScroll(
407+
@NonNull CoordinatorLayout coordinatorLayout,
408+
@NonNull V child,
409+
@NonNull View target,
410+
int type) {
396411
if (child.getTop() == getExpandedOffset()) {
397412
setStateInternal(STATE_EXPANDED);
398413
return;
@@ -452,7 +467,11 @@ public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, V child, Vie
452467

453468
@Override
454469
public boolean onNestedPreFling(
455-
CoordinatorLayout coordinatorLayout, V child, View target, float velocityX, float velocityY) {
470+
@NonNull CoordinatorLayout coordinatorLayout,
471+
@NonNull V child,
472+
@NonNull View target,
473+
float velocityX,
474+
float velocityY) {
456475
return target == nestedScrollingChildRef.get()
457476
&& (state != STATE_EXPANDED
458477
|| super.onNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY));
@@ -721,7 +740,7 @@ void startSettlingAnimation(View child, int state) {
721740
new ViewDragHelper.Callback() {
722741

723742
@Override
724-
public boolean tryCaptureView(View child, int pointerId) {
743+
public boolean tryCaptureView(@NonNull View child, int pointerId) {
725744
if (state == STATE_DRAGGING) {
726745
return false;
727746
}
@@ -739,7 +758,8 @@ public boolean tryCaptureView(View child, int pointerId) {
739758
}
740759

741760
@Override
742-
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
761+
public void onViewPositionChanged(
762+
@NonNull View changedView, int left, int top, int dx, int dy) {
743763
dispatchOnSlide(top);
744764
}
745765

@@ -751,7 +771,7 @@ public void onViewDragStateChanged(int state) {
751771
}
752772

753773
@Override
754-
public void onViewReleased(View releasedChild, float xvel, float yvel) {
774+
public void onViewReleased(@NonNull View releasedChild, float xvel, float yvel) {
755775
int top;
756776
@State int targetState;
757777
if (yvel < 0) { // Moving up
@@ -816,18 +836,18 @@ public void onViewReleased(View releasedChild, float xvel, float yvel) {
816836
}
817837

818838
@Override
819-
public int clampViewPositionVertical(View child, int top, int dy) {
839+
public int clampViewPositionVertical(@NonNull View child, int top, int dy) {
820840
return MathUtils.constrain(
821841
top, getExpandedOffset(), hideable ? parentHeight : collapsedOffset);
822842
}
823843

824844
@Override
825-
public int clampViewPositionHorizontal(View child, int left, int dx) {
845+
public int clampViewPositionHorizontal(@NonNull View child, int left, int dx) {
826846
return child.getLeft();
827847
}
828848

829849
@Override
830-
public int getViewVerticalDragRange(View child) {
850+
public int getViewVerticalDragRange(@NonNull View child) {
831851
if (hideable) {
832852
return parentHeight;
833853
} else {

0 commit comments

Comments
 (0)