In my iOS App i want to place two views of the same width so that they fill the entire width of the parent view.
For this I use GeometryReader and it broke auto layout. But auto layout does not work and the height of this view is not calculated automatically. Height of TestView is not determined, so i cant add frame size manually...
Here's what it should look like (what i expect TestView):
This is what it looks like when I put a view on a list (CurrenciesView):
TestView.swift
struct TestView: View {
var body: some View {
GeometryReader { geometry in
HStack(spacing: 0) {
VStack(alignment: .leading, spacing: 0.0) {
Text("Name 1\n Test second name 2")
.font(.system(size: 18))
.fontWeight(.bold)
HStack {
Text("123")
Text(" + 5")
}
}
.padding(.horizontal, 12.0)
.padding(.vertical, 9.0)
.frame(width: geometry.size.width / 2)
.background(RoundedRectangle(cornerRadius: 8.0)
.foregroundColor(Color.blue
.opacity(0.2)))
VStack(alignment: .leading, spacing: 0.0) {
Text("Name 1")
.font(.system(size: 18))
.fontWeight(.bold)
HStack {
Text("123")
Text(" + 5")
}
}
.padding(.horizontal, 12.0)
.padding(.vertical, 9.0)
.frame(width: geometry.size.width / 2)
.background(RoundedRectangle(cornerRadius: 8.0)
.foregroundColor(Color.blue
.opacity(0.2)))
}
}
}
}
CurrenciesView.swift
struct CurrenciesView: View {
@State private var items: [Str] = (0..<5).map { i in
return Str(title: "Struct #\(i)")
}
var body: some View {
NavigationView {
List {
Section(header:
TestView().listRowInsets(EdgeInsets())
) {
ForEach(items) { item in
Text("asd")
}
}.clipped()
}
.navigationBarTitle("Section Name")
.navigationBarItems(trailing: EditButton())
}
}
}