we are using solution proposed here: https://github.com/onmyway133/blog/issues/769#issue-802788982
import SwiftUI
struct HSearchBar: View {
@State
private var scrollViewContentSize: CGSize = .zero
var body: some View {
HStack {
searchButton
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 12) {
ForEach(store.collections) { collection in
collectionCell(collection)
}
}
.background(
GeometryReader { geo -> Color in
DispatchQueue.main.async {
scrollViewContentSize = geo.size
}
return Color.clear
}
)
}
.frame(
maxWidth: scrollViewContentSize.width
)
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: