Move setup for Android sheet (#5684)

This commit is contained in:
Hailey
2024-10-10 17:52:19 -07:00
committed by GitHub
parent 2a3f9b38e6
commit 34a0007679
@@ -155,21 +155,26 @@ class BottomSheetView(
if (this.isOpen || this.isOpening || this.isClosing) return
val contentHeight = this.getContentHeight()
val dialog = BottomSheetDialog(context)
dialog.setContentView(dialogRootViewGroup)
dialog.setCancelable(!preventDismiss)
dialog.setOnShowListener {
dialog.setOnDismissListener {
this.isClosing = true
this.destroy()
}
val bottomSheet = dialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
bottomSheet?.let {
// Let the outside view handle the background color on its own, the default for this is
// white and we don't want that.
it.setBackgroundColor(0)
val behavior = BottomSheetBehavior.from(it)
behavior.state = BottomSheetBehavior.STATE_HIDDEN
behavior.isFitToContents = true
behavior.halfExpandedRatio = this.clampRatio(this.getTargetHeight() / this.screenHeight)
behavior.skipCollapsed = true
behavior.isDraggable = true
behavior.isHideable = true
if (contentHeight > this.screenHeight) {
behavior.state = BottomSheetBehavior.STATE_EXPANDED
this.selectedSnapPoint = 2
@@ -177,9 +182,6 @@ class BottomSheetView(
behavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
this.selectedSnapPoint = 1
}
behavior.skipCollapsed = true
behavior.isDraggable = true
behavior.isHideable = true
behavior.addBottomSheetCallback(
object : BottomSheetBehavior.BottomSheetCallback() {
@@ -210,12 +212,6 @@ class BottomSheetView(
},
)
}
}
dialog.setOnDismissListener {
this.isClosing = true
this.destroy()
}
this.isOpening = true
dialog.show()
this.dialog = dialog