I have a VStack with three children. Each of those children have an HStack with some text and an empty space on the left. Here is a screenshot of the preview with a highlighted border around a VStack child, and one with a highlighted border around each HStack.
How do I set each VStack child to shrink to the height of the HStack and get rid of the empty space on the bottom? Right now the problem seems to be caused by the VStack by default filling the entire screen and setting each child to equal height.
Current Code:
import Foundation
import SwiftUI
struct NameAndConnection: View {
var body: some View {
VStack(alignment: .leading) {
Text(data.name)
.font(.headline)
.fontWeight(.semibold)
.foregroundColor(Color.black)
.frame(alignment: .leading)
Text(data.connection)
.font(.callout)
.fontWeight(.medium)
.foregroundColor(Color.gray)
.frame(alignment: .leading)
}
}
}
struct Description: View {
var body: some View {
Text(data.description)
}
}
struct Post: View {
var body: some View {
GeometryReader { geo in
HStack(alignment: .top, spacing: 0) {
Spacer()
VStack(alignment: .leading) {
NameAndConnection()
Description()
.padding(.top, 1.0)
}
.frame(width: geo.size.width * 0.75)
}
}
}
}
struct PostView: View {
var body: some View {
GeometryReader { geo in
VStack() {
Post()
Post()
Post()
}
}
}
}