My App uses GeometryReader with some padding to setup a View frame dimension inside a NavigationView.
Since iOS 14 i get the following error message:
Invalid frame dimension (negative or non-finite)
Here is some example code to test:
import SwiftUI
struct ContentView: View {
let padding:CGFloat = 16.0
var body: some View {
NavigationView {
GeometryReader { p in
Text("Hello, world!")
.frame(width: p.size.width - padding)
.padding()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Removing NavigationView fix the problem, but I need the current width and height of the container View inside the NavigationView.
Any suggestion?
I think it might be a static analysis issue as .frame(width: p.size.width - padding)
could result in a negative value. Try:
.frame(width: abs(p.size.width - padding))
When I tested with macOS 11.1, I found that GeometryReader
could not return the actual size immediately at the beginning of the view init, the size obtained for the first time was incorrect, maybe need to do a dispatch async operation to avoid this warning
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With