Skip to content

Commit ffb423d

Browse files
Fixed scrolling issues.
1 parent a1275fc commit ffb423d

11 files changed

Lines changed: 159 additions & 35 deletions

File tree

.idea/misc.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.buggysofts.bottomsheetmenu;
2+
3+
import android.content.Context;
4+
import android.util.AttributeSet;
5+
import android.view.MotionEvent;
6+
import android.widget.AbsListView;
7+
import android.widget.ListView;
8+
9+
public class BottomSheetListView extends ListView {
10+
11+
public BottomSheetListView(Context context) {
12+
super(context);
13+
}
14+
15+
public BottomSheetListView(Context context, AttributeSet attrs) {
16+
super(context, attrs);
17+
}
18+
19+
public BottomSheetListView(Context context, AttributeSet attrs, int defStyle) {
20+
super(context, attrs, defStyle);
21+
}
22+
23+
@Override
24+
public boolean onInterceptTouchEvent(MotionEvent ev) {
25+
return true;
26+
}
27+
28+
@Override
29+
public boolean onTouchEvent(MotionEvent ev) {
30+
if (canScrollVertically(this)) {
31+
getParent().requestDisallowInterceptTouchEvent(true);
32+
}
33+
return super.onTouchEvent(ev);
34+
}
35+
36+
@Override
37+
public boolean performClick() {
38+
return super.performClick();
39+
}
40+
41+
private boolean canScrollVertically(AbsListView view) {
42+
boolean canScroll = false;
43+
if (view != null && view.getChildCount() > 0) {
44+
boolean isOnTop = view.getFirstVisiblePosition() != 0 || view.getChildAt(0).getTop() != 0;
45+
boolean isAllItemsVisible = isOnTop && view.getLastVisiblePosition() == view.getChildCount();
46+
if (isOnTop || isAllItemsVisible) {
47+
canScroll = true;
48+
}
49+
}
50+
return canScroll;
51+
}
52+
}

BottomSheetMenu/src/main/java/com/buggysofts/bottomsheetmenu/BottomSheetMenu.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.view.MenuItem;
1111
import android.view.View;
1212
import android.widget.AdapterView;
13+
import android.widget.FrameLayout;
1314
import android.widget.LinearLayout;
1415
import android.widget.ListView;
1516
import android.widget.TextView;
@@ -21,9 +22,9 @@
2122
import androidx.appcompat.content.res.AppCompatResources;
2223
import androidx.appcompat.widget.PopupMenu;
2324

25+
import com.google.android.material.bottomsheet.BottomSheetBehavior;
2426
import com.google.android.material.bottomsheet.BottomSheetDialog;
2527

26-
import java.net.InterfaceAddress;
2728
import java.util.ArrayList;
2829
import java.util.List;
2930

@@ -35,6 +36,7 @@ public class BottomSheetMenu {
3536
private final Menu mainMenu;
3637
// main root view, menu list view
3738
private final View mainView;
39+
private final FrameLayout bottomSheetContentRoot;
3840
private final ListView menuList;
3941
private final View headerView;
4042
private final View footerView;
@@ -233,6 +235,9 @@ public BottomSheetMenu(@NonNull Context context,
233235
R.layout.menu_footer_view,
234236
null
235237
);
238+
bottomSheetContentRoot = mainView.findViewById(
239+
R.id.bottom_sheet_content_root
240+
);
236241
menuList = mainView.findViewById(
237242
R.id.menu_list
238243
);
@@ -248,6 +253,7 @@ public BottomSheetMenu(@NonNull Context context,
248253

249254
dialog = new BottomSheetDialog(context);
250255
dialog.setContentView(mainView);
256+
dialog.getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED);
251257
}
252258

253259
// init listeners
Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:layout_width="match_parent"
5-
android:layout_height="wrap_content"
6-
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior">
5+
android:layout_height="match_parent">
76

8-
<ListView
9-
android:id="@+id/menu_list"
10-
android:layout_width="0dp"
11-
android:layout_height="wrap_content"
12-
app:layout_constraintBottom_toBottomOf="parent"
13-
app:layout_constraintEnd_toEndOf="parent"
14-
app:layout_constraintStart_toStartOf="parent"
15-
app:layout_constraintTop_toTopOf="parent"
16-
android:divider="@null"></ListView>
17-
</androidx.constraintlayout.widget.ConstraintLayout>
7+
<FrameLayout
8+
android:id="@+id/bottom_sheet_content_root"
9+
android:layout_width="match_parent"
10+
android:layout_height="match_parent">
11+
12+
<com.buggysofts.bottomsheetmenu.BottomSheetListView
13+
android:id="@+id/menu_list"
14+
android:layout_width="match_parent"
15+
android:layout_height="match_parent"
16+
app:layout_constraintBottom_toBottomOf="parent"
17+
app:layout_constraintEnd_toEndOf="parent"
18+
app:layout_constraintStart_toStartOf="parent"
19+
app:layout_constraintTop_toTopOf="parent"
20+
android:divider="@null" />
21+
</FrameLayout>
22+
</androidx.coordinatorlayout.widget.CoordinatorLayout>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Finally, add this dependency to your app/module level build.gradle file
3434
3535
dependencies {
3636
...
37-
implementation 'com.github.buggysofts-com:BottomSheetMenu:v1.0.5'
37+
implementation 'com.github.buggysofts-com:BottomSheetMenu:v1.0.6'
3838
}
3939
```
4040
And you are done importing the library.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android {
1010
minSdk 21
1111
targetSdk 32
1212
versionCode 4
13-
versionName "1.0.5"
13+
versionName "1.0.6"
1414

1515
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616
}

app/src/main/java/com/buggysofts/bottomsheetmenuimpl/MainActivity.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package com.buggysofts.bottomsheetmenuimpl;
22

33
import android.graphics.Color;
4-
import android.graphics.drawable.Drawable;
54
import android.os.Bundle;
6-
import android.view.LayoutInflater;
75
import android.view.MenuItem;
86
import android.view.View;
97
import android.widget.Button;
108
import android.widget.Toast;
119

1210
import androidx.annotation.Nullable;
1311
import androidx.appcompat.app.AppCompatActivity;
14-
import androidx.appcompat.content.res.AppCompatResources;
1512

1613
import com.buggysofts.bottomsheetmenu.BottomSheetMenu;
1714

@@ -37,7 +34,8 @@ private void initialize() {
3734
public void onClick(View v) {
3835
showBuilderBasedMenu();
3936
}
40-
private void showFullConstructorBasedMenu(){
37+
38+
private void showFullConstructorBasedMenu() {
4139
try {
4240
new BottomSheetMenu(
4341
MainActivity.this,
@@ -73,11 +71,12 @@ public void onClick(MenuItem item) {
7371
e.printStackTrace();
7472
}
7573
}
76-
private void showBuilderBasedMenu(){
74+
75+
private void showBuilderBasedMenu() {
7776
try {
7877
new BottomSheetMenu(
7978
MainActivity.this,
80-
R.menu.sample_menu,
79+
R.menu.data_package_restore_options_menu,
8180
new BottomSheetMenu.MenuItemClickListener() {
8281
@Override
8382
public void onClick(MenuItem item) {
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
<vector android:height="24dp" android:tint="#000000"
2-
android:viewportHeight="24" android:viewportWidth="24"
3-
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4-
<path android:fillColor="@android:color/white" android:pathData="M17.6,9.48l1.84,-3.18c0.16,-0.31 0.04,-0.69 -0.26,-0.85c-0.29,-0.15 -0.65,-0.06 -0.83,0.22l-1.88,3.24c-2.86,-1.21 -6.08,-1.21 -8.94,0L5.65,5.67c-0.19,-0.29 -0.58,-0.38 -0.87,-0.2C4.5,5.65 4.41,6.01 4.56,6.3L6.4,9.48C3.3,11.25 1.28,14.44 1,18h22C22.72,14.44 20.7,11.25 17.6,9.48zM7,15.25c-0.69,0 -1.25,-0.56 -1.25,-1.25c0,-0.69 0.56,-1.25 1.25,-1.25S8.25,13.31 8.25,14C8.25,14.69 7.69,15.25 7,15.25zM17,15.25c-0.69,0 -1.25,-0.56 -1.25,-1.25c0,-0.69 0.56,-1.25 1.25,-1.25s1.25,0.56 1.25,1.25C18.25,14.69 17.69,15.25 17,15.25z"/>
1+
<vector android:height="24dp"
2+
android:tint="#000000"
3+
android:viewportHeight="24"
4+
android:viewportWidth="24"
5+
android:width="24dp"
6+
xmlns:android="http://schemas.android.com/apk/res/android">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M17.6,9.48l1.84,-3.18c0.16,-0.31 0.04,-0.69 -0.26,-0.85c-0.29,-0.15 -0.65,-0.06 -0.83,0.22l-1.88,3.24c-2.86,-1.21 -6.08,-1.21 -8.94,0L5.65,5.67c-0.19,-0.29 -0.58,-0.38 -0.87,-0.2C4.5,5.65 4.41,6.01 4.56,6.3L6.4,9.48C3.3,11.25 1.28,14.44 1,18h22C22.72,14.44 20.7,11.25 17.6,9.48zM7,15.25c-0.69,0 -1.25,-0.56 -1.25,-1.25c0,-0.69 0.56,-1.25 1.25,-1.25S8.25,13.31 8.25,14C8.25,14.69 7.69,15.25 7,15.25zM17,15.25c-0.69,0 -1.25,-0.56 -1.25,-1.25c0,-0.69 0.56,-1.25 1.25,-1.25s1.25,0.56 1.25,1.25C18.25,14.69 17.69,15.25 17,15.25z" />
510
</vector>
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
<vector android:height="24dp" android:tint="#000000"
2-
android:viewportHeight="24" android:viewportWidth="24"
3-
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4-
<path android:fillColor="@android:color/white" android:pathData="M2,20h20v-4L2,16v4zM4,17h2v2L4,19v-2zM2,4v4h20L22,4L2,4zM6,7L4,7L4,5h2v2zM2,14h20v-4L2,10v4zM4,11h2v2L4,13v-2z"/>
1+
<vector android:height="24dp"
2+
android:tint="#000000"
3+
android:viewportHeight="24"
4+
android:viewportWidth="24"
5+
android:width="24dp"
6+
xmlns:android="http://schemas.android.com/apk/res/android">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M2,20h20v-4L2,16v4zM4,17h2v2L4,19v-2zM2,4v4h20L22,4L2,4zM6,7L4,7L4,5h2v2zM2,14h20v-4L2,10v4zM4,11h2v2L4,13v-2z" />
510
</vector>
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
<vector android:height="24dp" android:tint="#000000"
2-
android:viewportHeight="24" android:viewportWidth="24"
3-
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4-
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
1+
<vector android:height="24dp"
2+
android:tint="#000000"
3+
android:viewportHeight="24"
4+
android:viewportWidth="24"
5+
android:width="24dp"
6+
xmlns:android="http://schemas.android.com/apk/res/android">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z" />
510
</vector>

0 commit comments

Comments
 (0)