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

1

10

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()
    }
}
Dentate answered 21/10, 2021 at 14:24 Comment(14)
Without a Minimal Reproducible Example it is impossible to help you troubleshoot. The NavigationLink in your code has no chance of working.Trahurn
Why ? It’s working perfectly in watchOS 7 or 8… If you could explain me why le code is false …Schach
Put that exact code into a blank project and see if it reproduces your issueTrahurn
If I cut/paste this code in a brand new watchOS project in Xcode 13, I immediately reproduce the issue if I run it to a real device with watchOS 8.1, and the code is working as expected in simulator (watchOS 7 or 8.0) or in a real device on watchOS 8.0. But if I have made a mistake, I will be happy to learn !Schach
Just one think is missing, the "@main" part which is the basic one created with each blank project.Schach
I have added the @main part of the code to be more complete ...Schach
The issue was the NavigationView not the @main. Try putting the NavigationView inside the TabView vs outside, each tab will need one. There are quite a few bugs mentioned in SO about a TabView inside the NavigationViewTrahurn
In this "easy" sample, your idea is a possible fix. But in my real app, I can't make it work. My app as a first screen which is a Navigation view with some navigation links. From this screen I open as .sheet a TabView. And one screen of this TabView contains a NavigationLink. So if I put a NavigationView into each tab of the TabView, it makes a conflict with the top level NavigationView required for the first screen. It was working perfectly for months, but Apple has changed something in watchOS 8.1 which breaks that ...Schach
I have updated the code with all the views I have in my architectureSchach
One more information. The app behaves normally on iOS 15.1 RC on a real device. The bug only occurs on watchOS 8.1RC on a real device.Schach
Witnessing same behavior in an app. Fine on devices with 8.0, those who upgraded to 8.1 and it pops back from the navigationlink view every time. Something changed with 8.1 on Apple side, since it worked all the way back to 7.3 (when we first implemented the UI for our app).Visby
Don’t forget to report the issue at Apple support.Schach
The problem remains in watchOS 8.3 beta1Schach
I am experiencing as well #69748039 and have filed Feedback #FB9727188Sik
O
1

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.

Obumbrate answered 12/11, 2021 at 10:44 Comment(1)
Thanks for this tip, but in my case it doesn’t give a good result. I have to wait for an Apple fix. I will test with last beta to check if it’s still broken. For the moment I use a weird workaround with a .sheetSchach

© 2022 - 2025 — McMap. All rights reserved.