In SwfitUI it is extremely easy to add a sheet layer on top of your current view. You just need to append the .sheet(...)
modifier to your view:
ZStack {
Text("My main view goes here")
}.sheet(isPresented: $shouldShowSheet) {
Text("My sheet content")
}
The sheet modifier accepts a boolean value as a binding and the content that should be displayed when the boolean value is true
.
If within the sheet view you want to programatically dismiss the sheet you can use the dismiss environment function provided:
struct CreateProjectView: View {
@Environment(\.dismiss) var dismiss
var body: some View {
HStack {
Text("My sheet")
Button(action: {dismiss()}) {
Text("Dismiss sheet")
}
}
}
}