Move setup for Android sheet (#5684)
This commit is contained in:
+10
-14
@@ -155,21 +155,26 @@ class BottomSheetView(
|
|||||||
if (this.isOpen || this.isOpening || this.isClosing) return
|
if (this.isOpen || this.isOpening || this.isClosing) return
|
||||||
|
|
||||||
val contentHeight = this.getContentHeight()
|
val contentHeight = this.getContentHeight()
|
||||||
|
|
||||||
val dialog = BottomSheetDialog(context)
|
val dialog = BottomSheetDialog(context)
|
||||||
dialog.setContentView(dialogRootViewGroup)
|
dialog.setContentView(dialogRootViewGroup)
|
||||||
dialog.setCancelable(!preventDismiss)
|
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)
|
val bottomSheet = dialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
|
||||||
bottomSheet?.let {
|
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)
|
it.setBackgroundColor(0)
|
||||||
|
|
||||||
val behavior = BottomSheetBehavior.from(it)
|
val behavior = BottomSheetBehavior.from(it)
|
||||||
|
behavior.state = BottomSheetBehavior.STATE_HIDDEN
|
||||||
behavior.isFitToContents = true
|
behavior.isFitToContents = true
|
||||||
behavior.halfExpandedRatio = this.clampRatio(this.getTargetHeight() / this.screenHeight)
|
behavior.halfExpandedRatio = this.clampRatio(this.getTargetHeight() / this.screenHeight)
|
||||||
|
behavior.skipCollapsed = true
|
||||||
|
behavior.isDraggable = true
|
||||||
|
behavior.isHideable = true
|
||||||
|
|
||||||
if (contentHeight > this.screenHeight) {
|
if (contentHeight > this.screenHeight) {
|
||||||
behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||||
this.selectedSnapPoint = 2
|
this.selectedSnapPoint = 2
|
||||||
@@ -177,9 +182,6 @@ class BottomSheetView(
|
|||||||
behavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
|
behavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
|
||||||
this.selectedSnapPoint = 1
|
this.selectedSnapPoint = 1
|
||||||
}
|
}
|
||||||
behavior.skipCollapsed = true
|
|
||||||
behavior.isDraggable = true
|
|
||||||
behavior.isHideable = true
|
|
||||||
|
|
||||||
behavior.addBottomSheetCallback(
|
behavior.addBottomSheetCallback(
|
||||||
object : BottomSheetBehavior.BottomSheetCallback() {
|
object : BottomSheetBehavior.BottomSheetCallback() {
|
||||||
@@ -210,12 +212,6 @@ class BottomSheetView(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
dialog.setOnDismissListener {
|
|
||||||
this.isClosing = true
|
|
||||||
this.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
this.isOpening = true
|
this.isOpening = true
|
||||||
dialog.show()
|
dialog.show()
|
||||||
this.dialog = dialog
|
this.dialog = dialog
|
||||||
|
|||||||
Reference in New Issue
Block a user