SwiftUI: Layout & Interfaces

Nov 18 2021 · Swift 5.5, iOS 15, Xcode 13

Part 1: Dynamic View Layout

04. Challenge: Nested Scrolling Stacks

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 03. ScrollViewReader Next episode: 05. Grids

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 04. Challenge: Nested Scrolling Stacks

Update Notes: This course was originally recorded in 2020. It has been reviewed and all content and materials updated as of October 2021.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

In Apple’s Music app, several views, like the ones for “Browsing”, and “Radio”, use layouts like this. They’re based around scrolling in Lazy Vertical Stacks, to make some kind of category visible.

    NavigationView {
      let genre = Genre.list.randomElement()!
LazyVStack {
      LazyVStack {
        Text(genre.name)
        Divider()
      }
        Text(genre.name)

        LazyHStack {

        }

        Divider()
        LazyHStack(spacing: 20) {
          ForEach(genre.subgenres, content: \.view)
        }
        ScrollView(.horizontal) {
          LazyHStack {
            ForEach(genre.subgenres, content: \.view)
          }
        }
    NavigationView {
      let genre = Genre.list.randomElement()!
      let horizontalPadding: CGFloat = 40

      LazyVStack {
LazyVStack(alignment: .leading) {
        Text(genre.name)
          .padding(.leading, horizontalPadding)
        Text(genre.name)
          .fontWeight(.heavy)
          .padding(.leading, horizontalPadding)
            ForEach(genre.subgenres, content: \.view)
          }
          .padding(.leading, horizontalPadding)
        }
        Divider()
          .padding(.horizontal, horizontalPadding)
      }
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 20) {
        Divider()
          .padding(.horizontal, horizontalPadding)
          .padding(.top)
      }
      LazyVStack(alignment: .leading) {
        ForEach(Genre.list) { genre in
          Text(genre.name)
            .fontWeight(.heavy)
            .padding(.leading, horizontalPadding)

          ScrollView(.horizontal, showsIndicators: false) {
            LazyHStack(spacing: 20) {
              ForEach(genre.subgenres, content: \.view)
            }
            .padding(.leading, horizontalPadding)
          }

          Divider()
            .padding(.horizontal, horizontalPadding)
            .padding(.top)
        }
      }
    NavigationView {
      let horizontalPadding: CGFloat = 40
    NavigationView {
      ScrollView {
        let horizontalPadding: CGFloat = 40
      }
      .padding(.top)
      .navigationBarTitleDisplayMode(.inline)
      ScrollView {
        ScrollViewReader { proxy in
          let horizontalPadding: CGFloat = 40
                .padding(.top)
            }
          }
          .onChange(of: selectedGenre) { genre in

          }
          .onChange(of: selectedGenre) { genre in
            withAnimation {
              proxy.scrollTo(genre, anchor: .top)
            }
          }
            withAnimation {
              proxy.scrollTo(genre, anchor: .top)
            }

            selectedGenre = nil
                .padding(.leading, horizontalPadding)
                .id(genre)

              ScrollView(.horizontal, showsIndicators: false) {