How would you make the .sheet presented above the tab bar wihtout covering it in SwiftUi? I’ve seen a somewhat solution but not one in SwiftUi.
So far anything I try just places the sheet overlaying the tab bar
import SwiftUI
struct ContentView: View {
@State private var showSheet = true
var body: some View {
TabView {
HomeView(showSheet: $showSheet)
.tabItem {
Label("Home", systemImage: "house")
}
Text("Second Tab")
.tabItem {
Label("Second", systemImage: "2.circle")
}
}
}
}
struct HomeView: View {
@Binding var showSheet: Bool
var body: some View {
VStack {
Button("Show TabView Sheet") {
showSheet.toggle()
}
.sheet(isPresented: $showSheet) {
SheetContent()
.presentationDetents([.medium, .large])
.interactiveDismissDisabled()
.presentationBackgroundInteraction(.enabled(upThrough: .large))
}
}
}
}
struct SheetContent: View {
var body: some View {
VStack {
Text("First Tab Content")
Text("More Content in the Sheet")
// Add more content here as needed
}
}
}
#Preview {
ContentView()
}
2
Answers
Based On Benzy Neez's answer, I also implemented smother animation and snapping points to make it look like a sheet. (Huge thanks to Benzy Neez)
In your example, the sheet cannot be dismissed interactively, but background interaction has been enabled. So I would suggest, an overlay could be used to replace the sheet:
EDIT You were asking in a comment if it would be possible to resize the overlay. You would need to implement this yourself using a drag gesture. Perhaps something like this: