-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): setup BottomSheetBehavior
- Loading branch information
Showing
6 changed files
with
104 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
android/src/main/java/com/lodev09/truesheet/TrueSheetBottomSheetBehavior.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.lodev09.truesheet | ||
|
||
import android.util.Log | ||
import android.view.MotionEvent | ||
import android.view.ViewGroup | ||
import android.widget.ScrollView | ||
import androidx.coordinatorlayout.widget.CoordinatorLayout | ||
import com.google.android.material.bottomsheet.BottomSheetBehavior | ||
|
||
class TrueSheetBottomSheetBehavior<T : ViewGroup>() : BottomSheetBehavior<T>() { | ||
|
||
private fun isInsideSheet(scrollView: ScrollView, event: MotionEvent): Boolean { | ||
val x = event.x | ||
val y = event.y | ||
|
||
val position = IntArray(2) | ||
scrollView.getLocationOnScreen(position) | ||
|
||
val nestedX = position[0] | ||
val nestedY = position[1] | ||
|
||
val boundRight = nestedX + scrollView.width | ||
val boundBottom = nestedY + scrollView.height | ||
|
||
return (x > nestedX && x < boundRight && y > nestedY && y < boundBottom) || | ||
event.action == MotionEvent.ACTION_CANCEL | ||
} | ||
|
||
// TODO: Pass scrollview explicitly here | ||
override fun onInterceptTouchEvent(parent: CoordinatorLayout, child: T, event: MotionEvent): Boolean { | ||
val isDownEvent = (event.actionMasked == MotionEvent.ACTION_DOWN) | ||
val expanded = state == STATE_EXPANDED | ||
|
||
if (isDownEvent && expanded){ | ||
val container = child.getChildAt(0) as ViewGroup | ||
val content = (container.getChildAt(0) as ViewGroup).getChildAt(0) as ViewGroup | ||
|
||
for(i in 0 until content.childCount){ | ||
val contentChild = content.getChildAt(i) | ||
val scrolled = (contentChild is ScrollView && contentChild.scrollY > 0) | ||
|
||
if(!scrolled) continue | ||
|
||
if (isInsideSheet(contentChild as ScrollView, event)) { | ||
return false | ||
} | ||
} | ||
} | ||
|
||
return super.onInterceptTouchEvent(parent, child, event) | ||
} | ||
|
||
companion object { | ||
const val TAG = "TrueSheetView" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters