SwiftUI: Layout & Interfaces, Episode 7: Challenge: Grids with Pinned Views | Kodeco, the new raywenderlich.com

Create a colorful, vertically-scrolling grid-based layout, which resembles the “Search” view from Apple Music.


This is a companion discussion topic for the original entry at https://www.kodeco.com/28684964-swiftui-layout-interfaces/lessons/7

At the end of the video, the instructor mentions that ScrollReader does not work properly. According to my observations, this happens when I select a genre which is at the bottom of the list – ie. not rendered yet due to Lazy Stacks.

I tried to fix this and it seemed to work if I put a guard around null value (when we set it to nil).

.onChange(of: selectedGenre) { genre in
  guard let selected = genre else {
     return
  }
  withAnimation {
    scrollProxy.scrollTo(selected, anchor: .top)
  }
  selectedGenre = nil
}
1 Like