TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

NavigationLink larger than its contents

Forums > SwiftUI

Hi everyone 👋 I'm a seasoned developer, but new to SwiftUI, and am developing an app for visionOS. What I can't figure out is why an image (or filled rectangle, or anything) placed inside a NavigationLink doesn't get its full width, but the width minus the corner radius. Here's my simplified code:

ScrollView(.vertical, showsIndicators: false) {
    LazyVGrid(columns: columns, spacing: 20) {
        ForEach(children, id: \.self) { childTopic in
            NavigationLink(value: childTopic) {
                Image(childTopic.previewImage)
                    .resizable()
                    .scaledToFill()
                    .frame(maxWidth: 300, maxHeight: 150, alignment: .top)
                    .clipShape(RoundedRectangle(cornerRadius: 15.0, style: .circular))
            }
            .buttonBorderShape(.roundedRectangle(radius: 15.0))
            .padding(20.0)
        }
    }
    .padding()
}

The screenshot shows what each list item looks like. Is it possible to make the image fill the NavigationLink?

PS: I played around with .buttonStyle(.plain) on the NavigationLink, but on visionOS it still gets an overlay when the user looks at it - which is a good thing, but larger than the image.

3      

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!

Reply to this topic…

You need to create an account or log in to reply.

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.