I'm trying to create a simple app for tvOS. But I immediately encountered difficulties. At the top I have a tab selection, and at the bottom there is item management.
The problem is that all buttons in HStack are connected into one big button.
So I solved it by adding .plain style to the buttons. But now I have a new problem - I can't focus on my buttons for tab selection.
Here is the code:
struct ContentView: View {
var body: some View {
VStack {
HStack (alignment: .center) {
Button("tab1"){}
Button("tab2"){}
}
.frame(width: 500) // works when remove
List {
HStack {
Text("Item 1")
Spacer()
Button("Button1"){}
.buttonStyle(.plain) // added
Button("Button2"){}
.buttonStyle(.plain) // added
}
HStack {
Text("Item 2")
Spacer()
Button("Button1"){}
.buttonStyle(.plain) // added
Button("Button2"){}
.buttonStyle(.plain) // added
}
}
}
}
}
I would appreciate any help. Unfortunately, there is very little information on the Internet about designing applications for tvOS, which confuses me.
The problem was that the focus could only move vertically or horizontally. And because of my .frame()
modifier, the buttons were positioned diagonally. The solution was to use .focusSection().
Here it's explained: https://developerinsider.co/swiftui-focussection-uifocusguide-alternative-for-swiftui/