ios – In SwiftUI, when the MyView popup sheet then dismissed, the MyView should be displayed instead of ListView


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

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img