SwiftUI tvOS ScrollView Not Scrolling Based On Apple Developer Documentation

Viewed 261

This should be a simple task. Following the example from the Apple Developers documentation (https://developer.apple.com/documentation/swiftui/scrollview), the data displayed doesn't scroll.

struct ContentView: View {

   var body: some View {
       ScrollView {
           VStack(alignment: .leading) {
               ForEach(0..<100) {
                   Text("Row \($0)")
               }
           }
       }
   }
}

I'm on Xcode 12.5.1. What am I missing here?

1 Answers

After much trial and error I finally figured out that each element needed to be focusable:

var body: some View {
    ScrollView(.vertical) {
        VStack(alignment: .leading) {
            ForEach(0..<100) {
                Text("Row \($0)")
                    .focusable()
            }
        }
    }
}

If there is another solution for this I'd love to hear it.

Related