dkk / WrappingHStack

A SwiftUI HStack with the ability to wrap contained elements

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use full width

Bryanx opened this issue · comments

commented

Hi, great job with this library :)

How can I make the items use the full width? so they stick to the right. I tried it with a Spacer, but it did not work.

WrappingHStack(alignment: .trailing, data: 1...20, id:\.self) {
    Text("Item: \($0)")
        .padding(.all, 20)
        .background(Rectangle().stroke())
}

Your image title

HI @Bryanx , that option is not implemented in the current state. I'll try to implement it for the next version. If you are up for it, I'd be glad if you would like to help.

The feature has been added by d1fc706

(update to 2.0.0 for this to work)

WrappingHStack(1...20, id:\.self, spacing: .dynamic(minSpacing: 8)) {
    Text("Item: \($0)")
        .padding(.all, 20)
        .background(Rectangle().stroke())
}

Screenshot 2021-04-17 at 19 12 24

commented

Hi thanks this is a big improvement, however not exactly what I was looking for. For example when aligning center right now it still sort of aligns horizontally:

WrappingHStack(1...20, id:\.self, alignment: .center) {
    Text("Item: \($0)")
        .padding(.all, 20)
        .background(Rectangle().stroke())
}

Your image title

Most ideal would be something like CSS flex is capable of:
Your image title

I will take a look if I can come up with a fork that implements this.

All these options are possible starting with 2.1.0. You can check out the example project to see how it works.

commented

Amazing this is perfect, thank you!