Skip to content

Commit ae84726

Browse files
committed
Honor sheet detents so a sheet fills the height it asked for
1 parent 65bc4c8 commit ae84726

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

  • Demo/swiftui/src/commonMain/kotlin/com/pureswift/swiftui

Demo/swiftui/src/commonMain/kotlin/com/pureswift/swiftui/Render.kt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
9090
import androidx.compose.material3.Icon
9191
import androidx.compose.material3.IconButton
9292
import androidx.compose.material3.ModalBottomSheet
93+
import androidx.compose.material3.rememberModalBottomSheetState
9394
import androidx.compose.material3.NavigationBar
9495
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
9596
import androidx.compose.material3.NavigationBarItem
@@ -1719,8 +1720,25 @@ private fun RenderSheetsAndAlerts(screen: ViewNode?) {
17191720
when (child.type) {
17201721
"Sheet" -> {
17211722
val onDismiss = child.long("onDismiss")
1722-
ModalBottomSheet(onDismissRequest = { onDismiss?.let { SwiftBridge.sink.invokeVoid(it) } }) {
1723-
child.children.firstOrNull()?.let { Render(it) }
1723+
// Detents were emitted but never read, so every sheet wrapped its
1724+
// content and a "full-size" sheet came up as a short strip.
1725+
val detents = child.stringArray("detents")
1726+
val medium = detents.contains("medium")
1727+
val large = detents.isEmpty() || detents.contains("large")
1728+
ModalBottomSheet(
1729+
onDismissRequest = { onDismiss?.let { SwiftBridge.sink.invokeVoid(it) } },
1730+
// with no medium detent there is no partial stop to rest at
1731+
sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = !medium),
1732+
) {
1733+
// A Material sheet is only as tall as its content, so one that
1734+
// should own the screen has to be told to fill it.
1735+
val height = when {
1736+
medium && !large -> Modifier.fillMaxHeight(0.5f)
1737+
else -> Modifier.fillMaxHeight()
1738+
}
1739+
Box(modifier = height) {
1740+
child.children.firstOrNull()?.let { Render(it) }
1741+
}
17241742
}
17251743
}
17261744
"Alert" -> RenderAlert(child)

0 commit comments

Comments
 (0)