dkk / WrappingHStack

A SwiftUI HStack with the ability to wrap contained elements
MIT License
486 stars 60 forks source link

Doesn't respect `Group` view #22

Open au5ton opened 2 years ago

au5ton commented 2 years ago

Describe the bug WrappingHStack treats the Group view as one view instead of its children.

To Reproduce Steps to reproduce the behavior:

// Code to reproduce bug
WrappingHStack {
  Group {
    Text("\(Image(systemName: "bag"))  Limit 1")
      .padding(.top, 5)
      .border(.red)
    Text("\(Image(systemName: "gearshape.2"))  Automatically used")
      .padding(.top, 5)
      .border(.red)
    Text("\(Image(systemName: "exclamationmark.circle"))  Sold out")
      .foregroundColor(Color.red)
      .padding(.top, 5)
      .border(.red)
  }
  .font(.system(size: 14, weight: .semibold))
  .foregroundColor(.secondary)
  .lineLimit(1)
  .border(.blue)
}

Spacer()

// Workaround (not bugged)
WrappingHStack(alignment: .trailing) {
  Text("\(Image(systemName: "bag"))  Limit 1")
    .padding(.top, 5)
    .border(.red)
  Text("\(Image(systemName: "gearshape.2"))  Automatically used")
    .padding(.top, 5)
    .border(.red)
  Text("\(Image(systemName: "exclamationmark.circle"))  Sold out")
    .foregroundColor(Color.red)
    .padding(.top, 5)
    .border(.red)
}
.font(.system(size: 14, weight: .semibold))
.foregroundColor(.secondary)
.lineLimit(1)
.border(.blue)

Expected behavior WrappingHStack would treat individual Text views as separate elements and provide spacing between them.

Screenshots Screenshot of code above:

Simulator Screen Shot - iPhone SE (2nd generation) - 2022-05-19 at 17 16 11 copy

Context:

Additional context

I understand that is a very quirky and specific edge case, but I thought I should report it just in case. I really wish Apple provided a native view for this. Coming from a web background, it seems really odd that iOS doesn't have something as comprehensive as CSS's flexbox.

Thank you for making this project! This package is such a lifesaver.

dkk commented 3 months ago

This is a known issue. I have not found a solution for it yet.