SwiftUI: WKWebView Cutting Off Page Content on macOS (NSViewRepresentable)
I had the exact same issue with WKWebView in MacOS app using SwiftUI.
The solution that worked for me is to use GeometryReader to get the exact height, and put the web view inside a scrollview (I believe it has something to do with the layout priority calculation, but couldn't get to the core of it yet).
Here is a snippet of what worked for me, maybe it will work with you as well
GeometryReader { g in
ScrollView {
BrowserView().tabItem {
Text("Browser")
}
.frame(height: g.size.height)
.tag(1)
}.frame(height: g.size.height)
}
webView.edgesIgnoringSafeArea(.all)
seems to work around this problem.
The solution by @Ahmed with GeometryReader
is quite elegant, yet I've found a shorter workaround.
struct BrowserView: View {
// ...
var body: some View {
// ...
browser.padding(-1.0)
// ...
}
}
Seems that the default padding, which equals to 0, causes this issue. So I just set it to -1.