I have a MainView which is a Navigation View and it presents a View through NavigationLink i.e. SubView here. In SubView, I want to present a view on top of the subview on a button toggle while hiding the navigation bar and the subview contents. I tried with ZStack but it doesn't seem to hide the navigation bar as it is still a part of the navigation stack. Is there any other way to achieve this?
The code looks like:
struct MainView: View {
var body: some View {
NavigationView {
List {
NavigationLink(destination: SubView()) {
Text("Go to Another View")
}
}
}
}
}
struct SubView : View {
@State private var showTopSheet: Bool = false
var body: some View {
ZStack {
Text("Content goes here")
if showTopSheet {
TopSheet(showTopSheet: $showTopSheet).transition(.move(edge: .top))
}
}.navigationBarTitle("SubView")
.navigationBarBackButtonHidden(true)
.navigationBarItems(trailing: Button(action: {
self.showTopSheet.toggle()
}) {
Image(systemName: "folder.circle")
})
}
}
struct TopSheet: View {
@Binding var showTopSheet: Bool
var body: some View {
GeometryReader { geo in
VStack {
ZStack {
Rectangle().fill(Color.orange)
.frame(height: geo.size.height * 364 / 744)
HStack {
Text("View")
Button(action: {
self.showTopSheet.toggle()
}) {
Image("Icon Close").renderingMode(.original)
}
}
}
Spacer()
}.edgesIgnoringSafeArea([.top, .bottom])
.background(Color(UIColor(red:0.1, green:0.1, blue:0.12, alpha:0.9)))
}
}
}
Thanks in advance :)