Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: BPKChip goes beyond its parent when the text is too long #2090

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Backpack-SwiftUI/Chip/Classes/ChipButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct ChipButtonStyle: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.frame(minHeight: .xl)
.fixedSize(horizontal: true, vertical: false)
.lineLimit(1)
.background(backgroundColor(configuration.isPressed))
.foregroundColor(foregroundColor(configuration.isPressed))
.clipShape(RoundedRectangle(cornerRadius: .sm))
Expand Down
13 changes: 9 additions & 4 deletions Backpack-SwiftUI/FlowStackView/Classes/BPKFlowStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ public struct BPKFlowStackView<Data: Collection, Content: View>: View where Data
let doesNotFitInCurrentRow = elementSize.width + spacing.width > remainingWidth

if doesNotFitInCurrentRow { // new row
remainingWidth = availableWidth
currentRow += 1
if rows.indices.contains(currentRow) {
Copy link
Contributor Author

@iHandle iHandle Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this element is the only element in the current row, we do not need to +1 to currentRow

currentRow += 1
remainingWidth = availableWidth
}
rows.append([Item(id: currentIndex, data: element)])
} else { // existing row
if !rows.indices.contains(currentRow) {
Expand Down Expand Up @@ -125,7 +127,10 @@ struct BPKFlowStackView_Previews: PreviewProvider {

@ViewBuilder
static func makeBadge(index: Int) -> some View {
BPKBadge("Hello" + Array(repeating: "👋", count: index % 5).joined())
.badgeStyle(.brand)
if index == 0 {
BPKChip(Array(repeating: "Hello", count: 15).joined(separator: " ")) { }
} else {
BPKChip("Hello" + Array(repeating: "👋", count: index % 5).joined()) { }
}
}
}
Loading