Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Commit 374b9c8

Browse files
authored
Merge pull request #20 from HeyAlex/restrict-touchable-area
restrict touchable area depends on translationX
2 parents 6444fb5 + a6eb937 commit 374b9c8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.materialstudies.owl.ui.lessons
2+
3+
import android.content.Context
4+
import android.util.AttributeSet
5+
import android.view.MotionEvent
6+
import android.view.View
7+
import androidx.coordinatorlayout.widget.CoordinatorLayout
8+
import com.google.android.material.bottomsheet.BottomSheetBehavior
9+
10+
/**
11+
* A [BottomSheetBehavior] that helps to restrict touchable area depends on translationX
12+
*/
13+
class LessonBottomSheetBehavior<T : View>(context: Context, attrs: AttributeSet?) :
14+
BottomSheetBehavior<T>(context, attrs) {
15+
16+
override fun onTouchEvent(parent: CoordinatorLayout, child: T, event: MotionEvent): Boolean {
17+
if (event.x < child.translationX) {
18+
return false
19+
}
20+
return super.onTouchEvent(parent, child, event)
21+
}
22+
}

Owl/app/src/main/res/layout/fragment_lessons_sheet.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
android:id="@+id/lessons_sheet"
3535
android:layout_height="match_parent"
3636
android:layout_width="match_parent"
37-
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
37+
app:layout_behavior="com.materialstudies.owl.ui.lessons.LessonBottomSheetBehavior"
3838
app:behavior_peekHeight="56dp">
3939

4040
<ImageView

0 commit comments

Comments
 (0)