blob: 1667006a56e7328028ac17848158addfd3ba509f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package com.google.android.material.bottomsheet;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import androidx.core.view.ViewCompat;
import androidx.viewpager.widget.ViewPager;
import java.lang.ref.WeakReference;
/**
* Override {@link #findScrollingChild(View)} to support {@link ViewPager}'s nested scrolling.
* In order to override package level method and field.
* This class put in the same package path where {@link BottomSheetBehavior} located.
* Source: https://medium.com/@hanru.yeh/funny-solution-that-makes-bottomsheetdialog-support-viewpager-with-nestedscrollingchilds-bfdca72235c3
*/
public class ViewPagerBottomSheetBehavior<V extends View> extends BottomSheetBehavior<V> {
public ViewPagerBottomSheetBehavior() {
super();
}
public ViewPagerBottomSheetBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
View findScrollingChild(View view) {
if (ViewCompat.isNestedScrollingEnabled(view)) {
return view;
}
if (view instanceof ViewPager) {
ViewPager viewPager = (ViewPager) view;
View currentViewPagerChild = viewPager.getChildAt(viewPager.getCurrentItem());
if (currentViewPagerChild != null) {
return findScrollingChild(currentViewPagerChild);
}
} else if (view instanceof ViewGroup) {
ViewGroup group = (ViewGroup) view;
for (int i = 0, count = group.getChildCount(); i < count; i++) {
View scrollingChild = findScrollingChild(group.getChildAt(i));
if (scrollingChild != null) {
return scrollingChild;
}
}
}
return null;
}
public void updateScrollingChild() {
final View scrollingChild = findScrollingChild(viewRef.get());
nestedScrollingChildRef = new WeakReference<>(scrollingChild);
}
}
|