Here is three view,ContentView,ListView and MyView。Click first bottom icon show ListView,then click NavigationLink display MyView.Click the button display sheet,dismiss the sheet the ListView displayed on the screen.
struct ContentView: View {
var body: some View {
NavigationView {
TabView {
ListView().tabItem {
Label("list view", systemImage: "face.smiling")
}
Text("list 2 content").tabItem {
Label("text", systemImage: "face.smiling")
}
}
}
}
}
struct ListView: View {
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
LazyHStack(alignment: .top) {
LazyVStack {
NavigationLink(destination: MyView()) {
Text("test")
}
}
}
}
}
}
struct MyView: View {
@State private var isShowingSheet = false
@Environment(\.presentationMode) var presentationMode
var body: some View {
Button(action: {
isShowingSheet.toggle()
}) {
Text("Show Sheet")
}
.sheet(isPresented: $isShowingSheet,
onDismiss: didDismiss)
{
VStack {
Text("License Agreement")
.font(.title)
.padding(50)
Text("""
Terms and conditions go here.
""")
.padding(50)
Button("Dismiss",
action: { isShowingSheet.toggle() })
}
}
}
func didDismiss() {
presentationMode.wrappedValue.dismiss()
}
}
In MyView sheet dismissed,should display MyView
It works for me if you re-organise the hierarchy as suggested in the comments and put the
NavigationViewinside theTabView, instead of vice versa.After the sheet is dismissed,
MyViewcan be seen again. However, it immediately navigates back toListViewdue to the.onDismissparameter to the.sheetmodifier. So if you don't want it to navigate back (perhaps for testing), remove the.onDismissparameter, or comment out the body ofdidDismiss: