UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Issue with NavigationLink in a LazyVGrid on MacOS

Forums > SwiftUI

@necka  

Hello,

i have an page that display a grid of TV Show posters. For this i use a LazyVGrid with adaptive columns

let columns = [
            GridItem(.adaptive(minimum: horizontalSizeClass == .compact ? 100 : 200))
        ]

And inside the cells i have a NavigationLink(value: xxx) and as a label a VStack with an image and a title. On iOS everything works well. On MacOS i only get a very small cell (like a single line of text button?) despite adding .frame modifier to try to force it. After some tyring i found out that removing the NavigationLink fixes the issue... but well i would like to navigate :)

I'm able to reproduce it with a simple view: LazyVGrid(columns: [GridItem(.adaptive(minimum: 200))], spacing: 20) {

LazyVGrid(columns: [GridItem(.adaptive(minimum: 200))], spacing: 20) {

              ForEach(1..<40) {item in
                  NavigationLink(value: item) {
                      VStack {
                          Text("OK")
                          Text("OK")
                          Text("OK")
                      }
                      /*PosterWithTitleView(title: item.UName, show: item, libraryService: libraryService)
                          .cornerRadius(5)*/

                  }
              }
          }

With NavigationLink

Without NavigationLink

Anyone experienced this issue?

1      

Try this modifier on the NavigationLink(value: item)

NavigationLink(value: item)  {
    // code here
}
.buttonStyle(.plain)

3      

@necka  

It works thanks!

1      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.