From a544b85b67a0baf22cc6cf5bb4649988320ee76d Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Sat, 2 Sep 2023 18:39:48 +0200 Subject: [PATCH] Don't dismiss bottom sheets when anchors change --- .../ui/component/BottomSheetDialog.kt | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/component/BottomSheetDialog.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/component/BottomSheetDialog.kt index 69ab970a..a75e43cd 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/component/BottomSheetDialog.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/component/BottomSheetDialog.kt @@ -222,14 +222,22 @@ fun BottomSheetDialog( oldValue == SwipeState.Full && hasPeekAnchor -> SwipeState.Peek else -> SwipeState.Dismiss } + val newAnchors = DraggableAnchors { + SwipeState.Dismiss at 0f + if (hasPeekAnchor) SwipeState.Peek at -min( + maxHeightPx * 0.5f, + sheetHeight + ) + if (hasFullAnchor) SwipeState.Full at -min(maxHeightPx, sheetHeight) + } draggableState.updateAnchors( - DraggableAnchors { - SwipeState.Dismiss at 0f - if (hasPeekAnchor) SwipeState.Peek at -min( - maxHeightPx * 0.5f, - sheetHeight - ) - if (hasFullAnchor) SwipeState.Full at -min(maxHeightPx, sheetHeight) + newAnchors, + with(draggableState) { + (if (!offset.isNaN()) { + newAnchors.closestAnchor(offset) ?: targetValue + } else targetValue).let { + if (it == SwipeState.Dismiss && targetValue != SwipeState.Dismiss && hasPeekAnchor) SwipeState.Peek else it + } }, ) if (newValue != oldValue) {