'Odd behavior with GeometryReader and Path
Could someone explain to me why a simple - 1 for container width fixes alignment problems with Color and Path in HStack.
Without -1 I get this, where the Path dissapears from the view:
But with the -1 it works as intended:
Full code:
struct SlantedBackground: View {
let color: Color
var body: some View {
GeometryReader { geometry in
HStack(spacing: 0) {
color
// This is where the problem is.
// This works
.frame(width: geometry.size.width - 1, height: geometry.size.height)
// This does not
.frame(width: geometry.size.width, height: geometry.size.height)
Path { path in
path.move(to: CGPoint(x: 0, y: 0))
path.addLine(to: CGPoint(x: 0, y: geometry.size.height))
path.addLine(to: CGPoint(x: 16, y: 0))
path.closeSubpath()
}.fill(color)
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


