-
-
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.
- Loading branch information
Showing
6 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
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,44 @@ | ||
package com.lodev09.truesheet | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.MotionEvent | ||
import android.view.View | ||
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> { | ||
|
||
constructor() : super() | ||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) | ||
|
||
override fun onInterceptTouchEvent(parent: CoordinatorLayout, child: T, event: MotionEvent): Boolean { | ||
val isDownEvent = (event.actionMasked == MotionEvent.ACTION_DOWN) | ||
val expanded = (state == BottomSheetBehavior.STATE_EXPANDED) | ||
|
||
if(isDownEvent && expanded){ | ||
val content = child.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 | ||
|
||
val inside = isMotionEventInsideView(contentChild, event) | ||
if(inside) return false | ||
} | ||
} | ||
|
||
return super.onInterceptTouchEvent(parent, child, event) | ||
} | ||
|
||
private fun isMotionEventInsideView(view: View, event: MotionEvent): Boolean { | ||
val coords = intArrayOf(0, 0) | ||
view.getLocationInWindow(coords) | ||
return ( | ||
event.rawX >= coords[0] && event.rawX <= (coords[0] + view.width) && | ||
event.rawY >= coords[1] && event.rawY <= (coords[1] + view.height) | ||
) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
android/src/main/java/com/lodev09/truesheet/TrueSheetView.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 |
---|---|---|
@@ -1,9 +1,32 @@ | ||
package com.lodev09.truesheet | ||
|
||
import android.content.Context | ||
import android.view.View | ||
import android.widget.RelativeLayout | ||
import com.google.android.material.bottomsheet.BottomSheetBehavior | ||
import androidx.coordinatorlayout.widget.CoordinatorLayout | ||
import com.google.android.material.bottomsheet.BottomSheetDialog | ||
|
||
class TrueSheetView(context: Context): CoordinatorLayout(context) { | ||
|
||
private lateinit var contents: RelativeLayout | ||
private set | ||
private lateinit var behavior: BottomSheetBehavior<*> | ||
private set | ||
|
||
override fun onViewAdded(child: View?) { | ||
super.onViewAdded(child) | ||
|
||
contents = child as RelativeLayout | ||
|
||
behavior = BottomSheetBehavior.from(contents).apply { | ||
// virtually disables 'third' breakpoint | ||
halfExpandedRatio = 0.9999999f | ||
isFitToContents = true | ||
isHideable = true | ||
// default to no collapsed state | ||
skipCollapsed = true | ||
setPeekHeight(Integer.MAX_VALUE) | ||
} | ||
} | ||
} |
5 changes: 4 additions & 1 deletion
5
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.lodev09.truesheet.TrueSheetView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<RelativeLayout | ||
android:id="@+id/contents" | ||
android:layout_gravity="center_horizontal" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layout_behavior="com.lodev09.truesheet.TrueSheetBottomSheetBehavior"/> | ||
|
||
</com.lodev09.truesheet.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