make hackfix more selective

This commit is contained in:
Samuel Newman
2025-05-07 15:28:15 +03:00
parent a8808b4df9
commit 3ca6c01fcc
@@ -254,8 +254,9 @@ class BottomSheetView(
slideOffset: Float, slideOffset: Float,
) { ) {
// Reset any translation we applied to fix initial position // Reset any translation we applied to fix initial position
// This ensures normal behavior once the user starts interacting // This should only happen in partial state, and only needs to be reset
if (bottomSheet.translationY != 0f) { // when the user starts interacting with the sheet
if (selectedSnapPoint == 1 && bottomSheet.translationY != 0f) {
bottomSheet.translationY = 0f bottomSheet.translationY = 0f
} }
} }
@@ -266,16 +267,19 @@ class BottomSheetView(
dialog.show() dialog.show()
this.dialog = dialog this.dialog = dialog
// When the sheet first opens, the position is too low - it's beneath the nav bars // When the sheet first opens at partial height, the position is too low - it's beneath the nav bars
// We fix by applying a translation initially, and then removing in `onSlide` // We fix by applying a translation initially, and then removing in `onSlide`
// since after the user starts interacting, it behaves properly. Probably not the neatest // since after the user starts interacting, it behaves properly. Probably not the neatest
// solution but seems to work consistently -sfn // solution but seems to work consistently -sfn
dialog.window?.decorView?.post { dialog.window?.decorView?.post {
val bottomSheet = dialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet) // Only apply the hack fix when in partial/half-expanded state (selectedSnapPoint == 1)
bottomSheet?.let { sheet -> if (selectedSnapPoint == 1) {
// Apply negative translation to counteract the navigation bar offset val bottomSheet = dialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
val navHeight = getNavigationBarHeight() bottomSheet?.let { sheet ->
sheet.translationY = -navHeight.toFloat() // Apply negative translation to counteract the navigation bar offset
val navHeight = getNavigationBarHeight()
sheet.translationY = -navHeight.toFloat()
}
} }
} }
} }