I am building a SwiftUI application for tvOS and am currently trying to implement UI. I have NavigationView at the bottom and label at the top and I want label to show which NavigationLink is currently in focus. Here is my code:
@State private var selection: String? = nil
.
ZStack {
Color.red.edgesIgnoringSafeArea(.all)
VStack {
Text(selection ?? "no value").background(Color.green)
NavigationView {
ScrollView(.horizontal) {
HStack{
VStack {
NavigationLink(destination: view2, tag: "1", selection: $selection) {
Image("placeholder")
.scaledToFit().frame(width:400, height: 225) }
Text("Button")
}
VStack {
NavigationLink(destination: view2, tag: "2", selection: $selection) {
Image("placeholder")
.scaledToFit().frame(width:400, height: 225) }
Text("Button")
}
...
}
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .bottomLeading)
}
}
}
}
However, label value doesn't change when I change selection and shows no value:
Any ideas what should I do there?