Trying to build a bar graph element in SwiftUI whose width is proportional to its parent view based on the value of the element. Here's a boiled down version of the problem:
struct BarView : View {
var body: some View {
Color.purple
.relativeWidth(0.5)
}
}
...which yields:
I expected the relativeWidth modifier to use its parent which should be the width of the screen, so the color view should be half the width of the screen and centered. If the view is embedded in a frame view, it works as expected:
struct BarView : View {
var body: some View {
Color.purple
.relativeWidth(0.5)
.frame(width: 200, height: 200)
}
}
I need the view to be flexible inside its container without specifying a frame. I realize there's the GeometryReader, but this seems like a bit of a hack when relativeWidth seems to be exactly what's needed here. Any ideas?

