Swift: How to change DetailView depending on SideBar Selection State with SwiftUI 4?

Context

I have a problem with the new SwiftUI SideBar / NavigationLink concept. I have created a simple 2 Column NavigationSplitView with a SideBar and a DetailView.

Once the App is launched, the preselected Timeline RootView appears as the DetailView. However, when I select a different SideBar Item, the DetailView does not change accordingly.


Code

struct SideBar: View {
    @State private var navigationItem: NavigationItem? = .timeline
    
    var body: some View {
        NavigationSplitView {
            List(NavigationItem.allCases, id: \.self, selection: $navigationItem) { navigationItem in
                NavigationLink(value: navigationItem) {
                    Label(navigationItem.name, systemImage: navigationItem.symbol)
                }
            }
        } detail: {
            if let safeNavigationItem = navigationItem {
                safeNavigationItem.rootView
            } else {
                Text(String(localized: "select.an.option", defaultValue: "Select an Option"))
            }
        }
    }
}

Question

Do you have any idea how I can solve this issue? Thanks a lot for your support in advance.

Note: Just ran it on macOS, it is working there. However, still not working on iPadOS.

Answered by szquest in 719943022

Conditional views in columns of NavigationSplitView fail to update on some state changes. (91311311)

Workaround: Wrap the contents of the column in a ZStack.

See iOS & iPadOS 16 Beta 3 Release Notes

Accepted Answer

Conditional views in columns of NavigationSplitView fail to update on some state changes. (91311311)

Workaround: Wrap the contents of the column in a ZStack.

See iOS & iPadOS 16 Beta 3 Release Notes

Swift: How to change DetailView depending on SideBar Selection State with SwiftUI 4?
 
 
Q