View using NavigationSplitView(sidebar:content:detail:) in SwiftUI on tvOS does not show the View in the content closure and does not allow proper navigation.
This occurs when NavigationSplitViewStyle is .automatic or .prominentDetail. It also occurs when not specified.
You can avoid using this sidebar style by adding .navigationSplitViewStyle(.balanced).
However, I would like to build an app employing this View.
I would be glad to know what you have noticed and if you have any advice.
Code
Here is the code to reproduce it Just replace it with this and somehow the phenomenon occurs.
import SwiftUI
struct ContentView: View {
@State var selected:Int?
@State var selected2:Int?
var body: some View {
NavigationSplitView {
List(selection: $selected){
NavigationLink(value: 1){
Label("1", systemImage: "1.circle")
}
NavigationLink(value: 2){
Label("2", systemImage: "2.circle")
}
NavigationLink(value: 3){
Label("3", systemImage: "3.circle")
}
}
.navigationTitle("Sidebar")
} content: {
if let selected = selected {
List(selection: $selected2){
NavigationLink(value: 1){
Label("1", systemImage: "1.square")
}
NavigationLink(value: 2){
Label("2", systemImage: "2.square")
}
NavigationLink(value: 3){
Label("3", systemImage: "3.square")
}
}
.navigationTitle("Content \(selected)")
} else {
Text("No Selected")
}
} detail: {
Group {
if let selected2 = selected2 {
Text(String(selected2))
}else{
Text("No Selected")
}
}
.navigationTitle("Detail")
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.navigationSplitViewStyle(.prominentDetail)
}
}
Environment
tvOS 18 Simulator (22J356)
macOS 15.1 beta (24B5055e)
Xcode 16.0 (16A242d)
How to Reproduce
- Open the attached project with Xcode.
- Build the project on Apple TV with Xcode.
- press any button on the sidebar
- Confirm that the View in the content closure is not displayed.
Actual Behavior
The View in the content closure is not displayed, and the View in the detail closure is displayed. (4/4)
Correct Behavior
The View in the content closure is displayed, and when the button of the View is pressed, the View in the detail closure is displayed.