diff options
author | Hailey <me@haileyok.com> | 2024-10-10 17:52:19 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-10 17:52:19 -0700 |
commit | 34a0007679311e2745ff7162a7ce2ae54f503125 (patch) | |
tree | ff8ce10c5fdc976d26d898ee1d39967a48cdbda0 /modules | |
parent | 2a3f9b38e627d925133c8a72726aeb472a6792bd (diff) | |
download | voidsky-34a0007679311e2745ff7162a7ce2ae54f503125.tar.zst |
Move setup for Android sheet (#5684)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/bottom-sheet/android/src/main/java/expo/modules/bottomsheet/BottomSheetView.kt | 102 |
1 files changed, 49 insertions, 53 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 a5a84ec3d..cfc89f5b3 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 @@ -155,67 +155,63 @@ class BottomSheetView( if (this.isOpen || this.isOpening || this.isClosing) return val contentHeight = this.getContentHeight() - val dialog = BottomSheetDialog(context) dialog.setContentView(dialogRootViewGroup) dialog.setCancelable(!preventDismiss) - dialog.setOnShowListener { - val bottomSheet = dialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet) - 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) - - val behavior = BottomSheetBehavior.from(it) - - behavior.isFitToContents = true - behavior.halfExpandedRatio = this.clampRatio(this.getTargetHeight() / this.screenHeight) - if (contentHeight > this.screenHeight) { - behavior.state = BottomSheetBehavior.STATE_EXPANDED - this.selectedSnapPoint = 2 - } else { - behavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED - this.selectedSnapPoint = 1 - } - behavior.skipCollapsed = true - behavior.isDraggable = true - behavior.isHideable = true - - behavior.addBottomSheetCallback( - object : BottomSheetBehavior.BottomSheetCallback() { - override fun onStateChanged( - bottomSheet: View, - newState: Int, - ) { - when (newState) { - BottomSheetBehavior.STATE_EXPANDED -> { - selectedSnapPoint = 2 - } - BottomSheetBehavior.STATE_COLLAPSED -> { - selectedSnapPoint = 1 - } - BottomSheetBehavior.STATE_HALF_EXPANDED -> { - selectedSnapPoint = 1 - } - BottomSheetBehavior.STATE_HIDDEN -> { - selectedSnapPoint = 0 - } - } - } - - override fun onSlide( - bottomSheet: View, - slideOffset: Float, - ) { } - }, - ) - } - } dialog.setOnDismissListener { this.isClosing = true this.destroy() } + val bottomSheet = dialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet) + bottomSheet?.let { + it.setBackgroundColor(0) + + val behavior = BottomSheetBehavior.from(it) + behavior.state = BottomSheetBehavior.STATE_HIDDEN + behavior.isFitToContents = true + behavior.halfExpandedRatio = this.clampRatio(this.getTargetHeight() / this.screenHeight) + behavior.skipCollapsed = true + behavior.isDraggable = true + behavior.isHideable = true + + if (contentHeight > this.screenHeight) { + behavior.state = BottomSheetBehavior.STATE_EXPANDED + this.selectedSnapPoint = 2 + } else { + behavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED + this.selectedSnapPoint = 1 + } + + behavior.addBottomSheetCallback( + object : BottomSheetBehavior.BottomSheetCallback() { + override fun onStateChanged( + bottomSheet: View, + newState: Int, + ) { + when (newState) { + BottomSheetBehavior.STATE_EXPANDED -> { + selectedSnapPoint = 2 + } + BottomSheetBehavior.STATE_COLLAPSED -> { + selectedSnapPoint = 1 + } + BottomSheetBehavior.STATE_HALF_EXPANDED -> { + selectedSnapPoint = 1 + } + BottomSheetBehavior.STATE_HIDDEN -> { + selectedSnapPoint = 0 + } + } + } + + override fun onSlide( + bottomSheet: View, + slideOffset: Float, + ) { } + }, + ) + } this.isOpening = true dialog.show() this.dialog = dialog |