SwiftUI | Navigation in TabView pops back when sheet dismissed

Viewed 24

It's really weird that when I use sheet inside navigated view from tab item, it always pops back itself.

Description

what I did was :

  1. Tap NavigationLink inside tab item view
  2. Show sheet from the navigated view
  3. Dismiss sheet
  4. View pops back automatically
import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            TabView {
                NavigationLink(destination: { TestView() }, label: { Text("Navigation link") })
                    .tabItem {
                        Image(systemName: "person")
                    }
            }
        }
    }
}

struct TestView: View {
    @State var show = false
    var body: some View {
        Button(action: { show = true }) {
            Text("Navigated view")
        }
        .sheet(isPresented: $show) {
            Text("Sheet view")
        }
    }
}

Then it happens:

enter image description here

Question

There're 2 requirements I want:

  1. Tab bar shouldn't be shown when navigate to another view.
  2. Use sheet the inside navigated view, not a fullScreenCover.

Is there any way to achieve them without facing the problems? Any advice will be appreciated. Thanks!

0 Answers
Related