fix screenHeight crash on API <30, wrong height on API <35
currentWindowMetrics requires API 30 — crashes on Android 9. Split into 3 tiers: - API 35+: heightPixels (reliable, edge-to-edge mandatory) - API 30-34: currentWindowMetrics (includes nav bar) - API <30: getRealSize (full display, pre-WindowMetrics) Also set elevation=0 on bottom sheet FrameLayout to remove Material shadow visible at the corners. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+13
-3
@@ -33,17 +33,27 @@ class BottomSheetView(
|
|||||||
private var eventDispatcher: EventDispatcher? = null
|
private var eventDispatcher: EventDispatcher? = null
|
||||||
|
|
||||||
// Native content height observation (eliminates JS bridge round-trip)
|
// Native content height observation (eliminates JS bridge round-trip)
|
||||||
private var contentLayoutListener: View.OnLayoutChangeListener? = null
|
private var contentLayoutListener: OnLayoutChangeListener? = null
|
||||||
private var observedChildren: List<View> = emptyList()
|
private var observedChildren: List<View> = emptyList()
|
||||||
private var lastObservedContentHeight: Float = 0f
|
private var lastObservedContentHeight: Float = 0f
|
||||||
private var pendingLayoutUpdate: Boolean = false
|
private var pendingLayoutUpdate: Boolean = false
|
||||||
|
|
||||||
private val screenHeight: Float =
|
private val screenHeight: Float =
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||||
|
// API 35+: edge-to-edge is mandatory, heightPixels is the full display
|
||||||
context.resources.displayMetrics.heightPixels.toFloat()
|
context.resources.displayMetrics.heightPixels.toFloat()
|
||||||
} else {
|
} else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
|
||||||
|
// API 30-34: heightPixels may exclude nav bar, use currentWindowMetrics
|
||||||
val wm = context.getSystemService(Context.WINDOW_SERVICE) as android.view.WindowManager
|
val wm = context.getSystemService(Context.WINDOW_SERVICE) as android.view.WindowManager
|
||||||
wm.currentWindowMetrics.bounds.height().toFloat()
|
wm.currentWindowMetrics.bounds.height().toFloat()
|
||||||
|
} else {
|
||||||
|
// API < 30: currentWindowMetrics not available, use getRealSize
|
||||||
|
// which includes system bars (heightPixels may exclude them)
|
||||||
|
val wm = context.getSystemService(Context.WINDOW_SERVICE) as android.view.WindowManager
|
||||||
|
val size = android.graphics.Point()
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
wm.defaultDisplay.getRealSize(size)
|
||||||
|
size.y.toFloat()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getNavigationBarHeight(): Int {
|
private fun getNavigationBarHeight(): Int {
|
||||||
@@ -355,7 +365,7 @@ class BottomSheetView(
|
|||||||
|
|
||||||
val innerViewGroup = this.innerView as? ViewGroup ?: return
|
val innerViewGroup = this.innerView as? ViewGroup ?: return
|
||||||
|
|
||||||
val listener = View.OnLayoutChangeListener { _, _, top, _, bottom, _, _, oldTop, oldBottom ->
|
val listener = OnLayoutChangeListener { _, _, top, _, bottom, _, _, oldTop, oldBottom ->
|
||||||
val newHeight = bottom - top
|
val newHeight = bottom - top
|
||||||
val oldHeight = oldBottom - oldTop
|
val oldHeight = oldBottom - oldTop
|
||||||
if (newHeight != oldHeight) {
|
if (newHeight != oldHeight) {
|
||||||
|
|||||||
Reference in New Issue
Block a user