Skip to content

Commit

Permalink
Merge pull request #20 from HeyAlex/restrict-touchable-area
Browse files Browse the repository at this point in the history
restrict touchable area depends on translationX
  • Loading branch information
hunterstich committed Jan 8, 2020
2 parents 6444fb5 + a6eb937 commit 374b9c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.materialstudies.owl.ui.lessons

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.google.android.material.bottomsheet.BottomSheetBehavior

/**
* A [BottomSheetBehavior] that helps to restrict touchable area depends on translationX
*/
class LessonBottomSheetBehavior<T : View>(context: Context, attrs: AttributeSet?) :
BottomSheetBehavior<T>(context, attrs) {

override fun onTouchEvent(parent: CoordinatorLayout, child: T, event: MotionEvent): Boolean {
if (event.x < child.translationX) {
return false
}
return super.onTouchEvent(parent, child, event)
}
}
2 changes: 1 addition & 1 deletion Owl/app/src/main/res/layout/fragment_lessons_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
android:id="@+id/lessons_sheet"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
app:layout_behavior="com.materialstudies.owl.ui.lessons.LessonBottomSheetBehavior"
app:behavior_peekHeight="56dp">

<ImageView
Expand Down

0 comments on commit 374b9c8

Please sign in to comment.