BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: How to get rid of NavigationLink space

Forums > SwiftUI

Folowing code

struct EditView: View {
    var body: some View {
          NavigationView {
                Form {
                      Section("Colors") {
                          ColorList(colors: viewModel.game.gameColors)
                      }
                }
          }
    }
}

struct ColorList: View {
    let colors: [String]

    private let gridItemLayout = [GridItem(.adaptive(minimum: 44))]

    var body: some View {
        ScrollView {
            LazyVGrid(columns: gridItemLayout) {
                ForEach(colors, id: \.self) { colorName in
                    Meeple(colorName: colorName)
                }
                .padding(.vertical, 2)
            }
        }
    }
}

// Meeple is just an image
struct Meeple: View {
    // ...
    var body: some View {
        Image("meeple.2.fill")
            .resizable()
            .padding(5)
            .foregroundColor(color.color)
            .background(color.backgroundColor)
            .frame(width: 44, height: 44, alignment: .center)
            .clipShape(RoundedRectangle(cornerRadius: 5))
            .shadow(color: .primary, radius: 5)
    }
}

works and gives me this result, which works well (actually for the detail view). screenshot-1

As soon as I add a NavigationLink around the ColorList like so

                Section("Colors") {
                    NavigationLink(destination:
                                    MultiColorPickerView(
                                        selection: $viewModel.game.colors.withDefaultValue([])
                                    )
                    ) {
                        ColorList(colors: viewModel.game.gameColors)
                    }
                }

The result looks weird: screenshot-2

There's plenty of space left. Why does it break after 3 items? And how can I make it to show more in one line?

   

Ok, this could be solved on SO with adding .frame(maxWidth: .infinity). Still would like to understand, why it's needed. My guess is, that there's an implicit "disclosure indicator" next to the content and both are treated equal. However a simple layoutPriority(1) on ColorList doen't change anything, so this hypothesis kinda fails.

   

Save 50% in my Black Friday sale.

SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.