Post

Replies

Boosts

Views

Activity

TabView with PageTabViewStyle action on NavigationLink not working on tvOS
Neither navigation or Button's actions working in the pages of the TabView with PageTabViewStyle. Repro code:     @State private var selection = 0     var body: some View {         VStack {             TabView(selection: $selection) {                 Button(action: {                     print("First selected")                 }){                     Text("Fist")                 }                 .tag(0)                 .buttonStyle(PlainButtonStyle()                 Button(action: {                     print("Second selected")                 }){                     Text("Second").tag(1)                 }                 .tag(1)                 Button(action: {                     print("Third selected")                 }){                     Text("Third")                 }                 .tag(2)             }             .tabViewStyle(PageTabViewStyle(indexDisplayMode: .always))             .frame(width: 900, height: 400)             .background(Color.blue)         }     } }
0
0
453
Nov ’20
Focus on the specific item in the List on SwiftUI (tvOS)
I am having a hard time trying to figured out how to focus on a specific cell/row in the list in the SwiftUI 2.0 and tvOS 14. I need to be able to focus and select a specific record when I am navigated to a view. However when the focus is switched to the list, some random row is focused. I've tried ScrollView and List to create a list of items with Buttons as items and with appropriate prefersDefaultFocus. Nothing works. Here's some sample code: struct ChannelListView: View {     @Namespace private var namespace     @ObservedObject var viewModel : LiveViewModel     @State var selection = Set<ChannelItem>()     var body: some View {         List(viewModel.channels, selection: $selection){ item in             ScrollViewReader { proxy in                         Button(action: {                         }){                             ChannelItemView(item: item, selectedItem: $viewModel.selectedChannel, onSelected: { id in                             })                             .padding(.vertical, 2)                         }                         .buttonStyle(ChannelButtonStyle())                         .prefersDefaultFocus(item == viewModel.selectedChannel, in: namespace)             }         }         .focusScope(namespace)     } } Any pointers?
0
0
1k
Oct ’20
tvOS 14 SwiftUI custom button style breaks scrolling back
I am trying to implement LazyHGrid on tvOS 14 with a pinned header. If I use standard buttons as grid items, the items scroll properly by changing its focus. However if I use my own custom style for the buttons, the first item is hidden behind the pinned header. Here's a repro code: struct ContentView: View { &#9;&#9;var rows: [GridItem] = [GridItem(.fixed(113))] &#9;&#9;@State private var selected : Bool = false &#9;&#9;@State private var isFocused : Bool = false &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack (alignment: .leading, spacing: 0) { &#9;&#9;&#9;&#9;&#9;&#9;ScrollView([.horizontal]) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;LazyHGrid (rows: rows, alignment: .top, spacing: 10, pinnedViews: .sectionHeaders, content: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(header: HeaderView(title: "NBC").border(Color.white)){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((0...20), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let codepoint = $0 + 0x1f600 &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let codepointString = String(format: "%02X", codepoint) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { print("selected")}) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;CellView(title: "\(codepointString)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} // Comment out this line - it will start working properly &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.buttonStyle(MyCustomButton()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9; }) &#9;&#9;&#9;&#9;&#9; } &#9;&#9;&#9;&#9;} &#9;&#9;} } struct HeaderView: View { &#9;&#9;@State var title : String &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;Text(title).frame(width: 160) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;.frame(maxWidth: .infinity, alignment: .topLeading) &#9;&#9;&#9;&#9;.frame(height: 113) &#9;&#9;&#9;&#9;.background(Color.blue) &#9;&#9;} } struct CellView : View { &#9;&#9;@Environment(\.isFocused) var isFocused: Bool &#9;&#9;@State var title : String &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack{ &#9;&#9;&#9;&#9;&#9;&#9;Text(title).font(.headline) &#9;&#9;&#9;&#9;&#9;&#9;Text("Very intersting movie") &#9;&#9;&#9;&#9;}.padding() &#9;&#9;&#9;&#9;.background(isFocused ? Color.gray : Color.red) &#9;&#9;} } struct MyCustomButton: ButtonStyle { &#9;&#9;func makeBody(configuration: Self.Configuration) -> some View { &#9;&#9;&#9;&#9;configuration.label &#9;&#9;&#9;&#9;&#9;&#9;.frame(minWidth: 0, maxWidth: 300) &#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(.white) &#9;&#9;&#9;&#9;&#9;&#9;.background(configuration.isPressed ? Color.red : Color.green) &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;} }
1
0
2k
Sep ’20