Skip to content

Commit 935d8e0

Browse files
committed
Fix bottom sheets detaching while content shrinks
1 parent 380028c commit 935d8e0

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

  • composeunstyled-bottom-sheet/src/commonMain/kotlin/com/composeunstyled

composeunstyled-bottom-sheet/src/commonMain/kotlin/com/composeunstyled/BottomSheet.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ class BottomSheetState internal constructor(
279279
private var sheetHeightDependentDetents: Set<SheetDetent> by mutableStateOf(emptySet())
280280
private var sheetHeightDependencyContainerHeightPx = Float.NaN
281281
private var sheetHeightDependencyDetents: List<SheetDetent> = emptyList()
282+
private var measuredContentHeightPx = Float.NaN
282283
private var measuredSheetHeightPx: Float by mutableStateOf(Float.NaN)
283284
internal var maxDetentHeightPx: Float by mutableStateOf(Float.NaN)
284285
internal var isDragging: Boolean by mutableStateOf(false)
@@ -525,8 +526,11 @@ class BottomSheetState internal constructor(
525526
}
526527

527528
internal fun updateContentHeight(measuredHeightPx: Float, includeMeasuredSheetHeight: Boolean) {
529+
val measuredContentHeightShrank = measuredContentHeightPx.isNaN().not() &&
530+
measuredHeightPx < measuredContentHeightPx
531+
measuredContentHeightPx = measuredHeightPx
528532
val shouldIncludeMeasuredSheetHeight = includeMeasuredSheetHeight ||
529-
measuredSheetHeightPx < containerHeightPx
533+
(measuredContentHeightShrank.not() && measuredSheetHeightPx < containerHeightPx)
530534
val measuredSheetHeight = if (shouldIncludeMeasuredSheetHeight) {
531535
measuredSheetHeightPx.takeUnless { it.isNaN() } ?: 0f
532536
} else {

0 commit comments

Comments
 (0)