Skip to content

GordonOnGithub/SwiftUIWebviewWithJSInterop

Repository files navigation

SwiftUIWebviewWithJSInterop

A WKWebView wrapper for SwiftUI with Javascript interoperability.

How To Use

  1. Create SwiftUIWithJSInteropWebViewModel, specify message handlers and the webview's URL.
  let url = URL(string: "your_webview_url")!
  
  let viewModel = SwiftUIWithJSInteropWebViewModel(url: url, messageHandlerNames: ["yourMessageHander"])
  1. Include SwiftUIWithJSInteropWebView along with SwiftUIWithJSInteropWebViewModel in your SwiftUI view.
struct ContentView: View {

  var body: some View {
    SwiftUIWithJSInteropWebView(viewModel: viewModel, navigationDelegate: nil)
  }
}
  1. Assign object that conforms SwiftUIWithJSInteropWebViewModelDelegate as SwiftUIWithJSInteropWebViewModel's delegate to handle messages from the webview.

  2. Evaluate javascript and load another URL into the webview via SwiftUIWithJSInteropWebViewModel as WebviewInteropInterface.

Check demo app project SwiftUIWebviewWithJSInteropDemo for complete code example.

About

A WKWebView wrapper for SwiftUI with Javascript interoperability

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published