Skip to content

Commit 1f09405

Browse files
committed
[iOS] - Fix layout of WrappingHStack when text becomes multi-line (#22608)
* Fix layout of WrappingHStack when text becomes multi-line. * Also fix spacing between items in the wrapping HStack on iOS 15 when line becomes multi-line. Signed-off-by: Brandon <[email protected]> Signed-off-by: Brandon T <[email protected]>
1 parent 40d4bd7 commit 1f09405

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

ios/brave-ios/Sources/AIChat/Components/Messages/AIChatSuggestionsView.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ struct WrappingHStack: Layout {
5252
}
5353

5454
var x = bounds.minX
55-
var y = height / 2.0 + bounds.minY
55+
var y = height + bounds.minY
5656

5757
subviews.forEach { subview in
5858
x += subview.dimensions(in: proposal).width / 2.0
5959

6060
if x + subview.dimensions(in: proposal).width / 2.0 > bounds.maxX {
6161
x = bounds.minX + subview.dimensions(in: proposal).width / 2.0
62-
y += height + vSpacing
62+
y += subview.dimensions(in: proposal).height + vSpacing
6363
}
6464

6565
subview.place(
6666
at: CGPoint(x: x, y: y),
67-
anchor: .center,
67+
anchor: .init(x: 0.5, y: 1.0),
6868
proposal: ProposedViewSize(
6969
width: subview.dimensions(in: proposal).width,
7070
height: subview.dimensions(in: proposal).height
@@ -124,25 +124,23 @@ struct WrappingHStackOld<Model, V>: View where Model: Hashable, V: View {
124124
ZStack(alignment: .topLeading) {
125125
ForEach(models, id: \.self) { model in
126126
viewGenerator(model)
127-
.padding(.horizontal, hSpacing)
128-
.padding(.vertical, vSpacing)
129127
.alignmentGuide(
130128
.leading,
131129
computeValue: { dimension in
132130
if abs(width - dimension.width) > geometry.size.width {
133131
width = 0.0
134-
height -= dimension.height
132+
height -= dimension.height + vSpacing
135133
}
136134

137135
let result = width
138-
width = model == models.last! ? 0.0 : width - dimension.width
136+
width = model == models.last! ? 0.0 : width - dimension.width - hSpacing
139137
return result
140138
}
141139
)
142140
.alignmentGuide(
143141
.top,
144142
computeValue: { dimension in
145-
let result = height
143+
let result = height + dimension.height
146144
if model == models.last! {
147145
height = 0.0
148146
}

0 commit comments

Comments
 (0)