From 3ca6c01fcc48b3de360140576aa078065828b33b Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 7 May 2025 15:28:15 +0300 Subject: [PATCH] make hackfix more selective --- .../modules/bottomsheet/BottomSheetView.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/bottom-sheet/android/src/main/java/expo/modules/bottomsheet/BottomSheetView.kt b/modules/bottom-sheet/android/src/main/java/expo/modules/bottomsheet/BottomSheetView.kt index 93e3a2519f..fd28d594af 100644 --- a/modules/bottom-sheet/android/src/main/java/expo/modules/bottomsheet/BottomSheetView.kt +++ b/modules/bottom-sheet/android/src/main/java/expo/modules/bottomsheet/BottomSheetView.kt @@ -254,8 +254,9 @@ class BottomSheetView( slideOffset: Float, ) { // Reset any translation we applied to fix initial position - // This ensures normal behavior once the user starts interacting - if (bottomSheet.translationY != 0f) { + // This should only happen in partial state, and only needs to be reset + // when the user starts interacting with the sheet + if (selectedSnapPoint == 1 && bottomSheet.translationY != 0f) { bottomSheet.translationY = 0f } } @@ -266,16 +267,19 @@ class BottomSheetView( dialog.show() 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` // since after the user starts interacting, it behaves properly. Probably not the neatest // solution but seems to work consistently -sfn dialog.window?.decorView?.post { - val bottomSheet = dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet) - bottomSheet?.let { sheet -> - // Apply negative translation to counteract the navigation bar offset - val navHeight = getNavigationBarHeight() - sheet.translationY = -navHeight.toFloat() + // Only apply the hack fix when in partial/half-expanded state (selectedSnapPoint == 1) + if (selectedSnapPoint == 1) { + val bottomSheet = dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet) + bottomSheet?.let { sheet -> + // Apply negative translation to counteract the navigation bar offset + val navHeight = getNavigationBarHeight() + sheet.translationY = -navHeight.toFloat() + } } } }