GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

SOLVED: How to get rid of NavigationLink space

Forums > SwiftUI

@kassi  

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?

2      

@kassi  

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.

2      

Hacking with Swift is sponsored by try! Swift Tokyo.

SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!

Get your ticket 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.