SwiftUI: NavigationLink pops out immediately on WatchOS 8.1RC in Tabview

Viewed 615

I have discovered a regression in watchOS 8.1RC with NavigationLink triggered from a TabView. It's immediately dismissed.

It was working in watchOS 8.0 or in Simulator (watchOS 8.0). Do you know a workaround ? Thanks

Sample code:

import SwiftUI

@main
struct TestNavigationApp: App {
    var body: some Scene {
        WindowGroup {
            NavigationView {
                ContentView()
            }
        }
    }
}

struct ContentView: View {
    var body: some View {
        List {
            NavigationLink(destination: ContentView1()) {
                Text("To TabView")
            }
        }
        
    }
}

struct ContentView1: View {
    var body: some View {
        TabView {
            NavigationView {
                NavigationLink(destination: ContentView2()) {
                    Text("To ContentView2")
                }
            }
            VStack {
                Text("Screen2")
            }
        }
    }
}

struct ContentView2: View {
    var body: some View {
        Text("ContentView2")
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
1 Answers

I'm experiencing the same issue with watchOS 8.1 (and 8.3 beta) while it was working with previous watchOS versions.

We were able to get it working again by moving the NavigationView inside the TabView. This workaround isn't ideal at all but it does seem to work.

@State private var tabSelection = 1

var body: some Scene {
    WindowGroup {
        TabView(selection: $tabSelection) {
            NavigationView {
                // List goes here
            }
            .tag(1)
            
            VStack(alignment: .center, spacing: 12, content: {
                
                // content 2nd tab: we didn't have a list in the 2nd tab
            })
            .tag(2)
        }
    }
}

However, there are 2 things impacted with this fix:

I didn't get the navigationBarTitle working, so there won't be a title on top of the screen. If you click on an item in the list, it will navigate to your page (as expected) but the TabView dots at the bottom of the screen will remain.

Related