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      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.