Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,34 @@ struct NavigationTests {
#expect(host.callbacks.callback(for: tap) != nil)
}

@Test("A sheet carries its detents, and none by default")
func sheetDetents() {
struct Screen: View {
@State var shown = true
var body: some View {
Button("Show") { shown = true }
.sheet(isPresented: $shown) {
Text("body").presentationDetents([.medium])
}
}
}
let node = ViewHost(Screen()).evaluate()
let sheet = node.children.first { $0.type == "Sheet" }
#expect(sheet?.props["detents"] == .array([.string("medium")]))

// no detents declared: the interpreter reads that as a full-height sheet
struct Plain: View {
@State var shown = true
var body: some View {
Button("Show") { shown = true }
.sheet(isPresented: $shown) { Text("body") }
}
}
let plain = ViewHost(Plain()).evaluate()
let plainSheet = plain.children.first { $0.type == "Sheet" }
#expect(plainSheet?.props["detents"] == .array([]))
}

@Test("TabView emits tabs with their item labels and selection")
func tabs() {
struct Screen: View {
Expand Down
22 changes: 20 additions & 2 deletions Demo/swiftui/src/commonMain/kotlin/com/pureswift/swiftui/Render.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.material3.NavigationBarItem
Expand Down Expand Up @@ -1719,8 +1720,25 @@ private fun RenderSheetsAndAlerts(screen: ViewNode?) {
when (child.type) {
"Sheet" -> {
val onDismiss = child.long("onDismiss")
ModalBottomSheet(onDismissRequest = { onDismiss?.let { SwiftBridge.sink.invokeVoid(it) } }) {
child.children.firstOrNull()?.let { Render(it) }
// Detents were emitted but never read, so every sheet wrapped its
// content and a "full-size" sheet came up as a short strip.
val detents = child.stringArray("detents")
val medium = detents.contains("medium")
val large = detents.isEmpty() || detents.contains("large")
ModalBottomSheet(
onDismissRequest = { onDismiss?.let { SwiftBridge.sink.invokeVoid(it) } },
// with no medium detent there is no partial stop to rest at
sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = !medium),
) {
// A Material sheet is only as tall as its content, so one that
// should own the screen has to be told to fill it.
val height = when {
medium && !large -> Modifier.fillMaxHeight(0.5f)
else -> Modifier.fillMaxHeight()
}
Box(modifier = height) {
child.children.firstOrNull()?.let { Render(it) }
}
}
}
"Alert" -> RenderAlert(child)
Expand Down
Loading