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()
    }
}
  • Without a [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) it is impossible to help you troubleshoot. The `NavigationLink` in your code has no chance of working. – lorem ipsum Oct 21 '21 at 15:44
  • Why ? It’s working perfectly in watchOS 7 or 8… If you could explain me why le code is false … – Raphaël Barthomeuf Oct 21 '21 at 15:54
  • Put that exact code into a blank project and see if it reproduces your issue – lorem ipsum Oct 21 '21 at 16:34
  • 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 ! – Raphaël Barthomeuf Oct 21 '21 at 16:42
  • Just one think is missing, the "@main" part which is the basic one created with each blank project. – Raphaël Barthomeuf Oct 21 '21 at 16:49
  • I have added the @main part of the code to be more complete ... – Raphaël Barthomeuf Oct 22 '21 at 06:12
  • 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 NavigationView – lorem ipsum Oct 22 '21 at 12:26
  • 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 ... – Raphaël Barthomeuf Oct 22 '21 at 15:09
  • I have updated the code with all the views I have in my architecture – Raphaël Barthomeuf Oct 23 '21 at 18:32
  • 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. – Raphaël Barthomeuf Oct 24 '21 at 10:05
  • 2
    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). – Brad Martin Oct 27 '21 at 15:26
  • Don’t forget to report the issue at Apple support. – Raphaël Barthomeuf Oct 27 '21 at 19:04
  • 2
    The problem remains in watchOS 8.3 beta1 – Raphaël Barthomeuf Oct 28 '21 at 08:09
  • I am experiencing as well https://stackoverflow.com/questions/69747539/swiftui-navigationview-bug-in-watchos-8-1-when-list-and-foreach-is-embedded-in and have filed Feedback #FB9727188 – GarySabo Oct 28 '21 at 19:07

1 Answers1

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.

O.Olivier
  • 230
  • 2
  • 12
  • 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 .sheet – Raphaël Barthomeuf Nov 17 '21 at 10:54