Hi Swift Community!
I'm excited to introduce WebUI - a powerful library for declaratively using WKWebView in SwiftUI.
WebUI is designed to align with existing SwiftUI interfaces such as ScrollView
and ScrollViewReader
. Therefore, its interfaces are intuitive for developers familiar with SwiftUI.
Key Features
- Declarative Syntax: Seamlessly integrate WKWebView with SwiftUI's declarative syntax.
- Intuitive API: Designed to feel natural for SwiftUI developers.
- Cross-Platform: Available for both iOS and macOS.
- Prevents Reinventing the Wheel: Avoid the redundant task of creating a SwiftUI wrapper for WKWebView by leveraging this well-designed library.
Quick Example
Here's a quick example:
struct ContentView: View {
var body: some View {
WebViewReader { proxy in
VStack(spacing: 16) {
Text(proxy.title ?? "")
HStack {
Button {
proxy.goBack()
} label: {
Label("Go Back", systemImage: "arrow.backward")
.labelStyle(.iconOnly)
}
.disabled(!proxy.canGoBack)
Spacer()
}
.padding(.horizontal)
WebView(request: URLRequest(url: URL(string: "https://forums.swift.org/")!))
.allowsBackForwardNavigationGestures(true)
.refreshable()
}
}
}
}
Get Started
The library is currently available for use on iOS and macOS. To learn more, please check out the documentation and the GitHub repository.
I look forward to your feedback and contributions!