remove safe/raw screen height distinction
This commit is contained in:
+11
-12
@@ -30,8 +30,7 @@ class BottomSheetView(
|
|||||||
private lateinit var dialogRootViewGroup: DialogRootViewGroup
|
private lateinit var dialogRootViewGroup: DialogRootViewGroup
|
||||||
private var eventDispatcher: EventDispatcher? = null
|
private var eventDispatcher: EventDispatcher? = null
|
||||||
|
|
||||||
private val rawScreenHeight = context.resources.displayMetrics.heightPixels.toFloat()
|
private val screenHeight = context.resources.displayMetrics.heightPixels.toFloat()
|
||||||
private val safeScreenHeight = rawScreenHeight
|
|
||||||
|
|
||||||
private fun getNavigationBarHeight(): Int {
|
private fun getNavigationBarHeight(): Int {
|
||||||
val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android")
|
val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android")
|
||||||
@@ -71,12 +70,12 @@ class BottomSheetView(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxHeight = this.safeScreenHeight
|
var maxHeight = this.screenHeight
|
||||||
set(value) {
|
set(value) {
|
||||||
val px = dpToPx(value)
|
val px = dpToPx(value)
|
||||||
field =
|
field =
|
||||||
if (px > this.safeScreenHeight) {
|
if (px > this.screenHeight) {
|
||||||
this.safeScreenHeight
|
this.screenHeight
|
||||||
} else {
|
} else {
|
||||||
px
|
px
|
||||||
}
|
}
|
||||||
@@ -164,13 +163,13 @@ class BottomSheetView(
|
|||||||
private fun getHalfExpandedRatio(contentHeight: Float): Float =
|
private fun getHalfExpandedRatio(contentHeight: Float): Float =
|
||||||
when {
|
when {
|
||||||
// Full height sheets
|
// Full height sheets
|
||||||
contentHeight >= safeScreenHeight -> 0.99f
|
contentHeight >= screenHeight -> 0.99f
|
||||||
// Medium height sheets (>50% but <100%)
|
// Medium height sheets (>50% but <100%)
|
||||||
contentHeight >= safeScreenHeight / 2 ->
|
contentHeight >= screenHeight / 2 ->
|
||||||
this.clampRatio(this.getTargetHeight() / safeScreenHeight)
|
this.clampRatio(this.getTargetHeight() / screenHeight)
|
||||||
// Small height sheets (<50%)
|
// Small height sheets (<50%)
|
||||||
else ->
|
else ->
|
||||||
this.clampRatio(this.getTargetHeight() / rawScreenHeight)
|
this.clampRatio(this.getTargetHeight() / screenHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun present() {
|
private fun present() {
|
||||||
@@ -224,7 +223,7 @@ class BottomSheetView(
|
|||||||
behavior.isDraggable = true
|
behavior.isDraggable = true
|
||||||
behavior.isHideable = true
|
behavior.isHideable = true
|
||||||
|
|
||||||
if (contentHeight >= this.safeScreenHeight || this.minHeight >= this.safeScreenHeight) {
|
if (contentHeight >= this.screenHeight || this.minHeight >= this.screenHeight) {
|
||||||
behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||||
this.selectedSnapPoint = 2
|
this.selectedSnapPoint = 2
|
||||||
} else {
|
} else {
|
||||||
@@ -304,9 +303,9 @@ class BottomSheetView(
|
|||||||
var newRatio = getHalfExpandedRatio(contentHeight)
|
var newRatio = getHalfExpandedRatio(contentHeight)
|
||||||
behavior.halfExpandedRatio = newRatio
|
behavior.halfExpandedRatio = newRatio
|
||||||
|
|
||||||
if (contentHeight > this.safeScreenHeight && behavior.state != BottomSheetBehavior.STATE_EXPANDED) {
|
if (contentHeight > this.screenHeight && behavior.state != BottomSheetBehavior.STATE_EXPANDED) {
|
||||||
behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||||
} else if (contentHeight < this.safeScreenHeight && behavior.state != BottomSheetBehavior.STATE_HALF_EXPANDED) {
|
} else if (contentHeight < this.screenHeight && behavior.state != BottomSheetBehavior.STATE_HALF_EXPANDED) {
|
||||||
behavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
|
behavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
|
||||||
} else if (currentState == BottomSheetBehavior.STATE_HALF_EXPANDED && oldRatio != newRatio) {
|
} else if (currentState == BottomSheetBehavior.STATE_HALF_EXPANDED && oldRatio != newRatio) {
|
||||||
behavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
|
behavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
|
||||||
|
|||||||
Reference in New Issue
Block a user