![](/style/images/good.png)
![](/style/images/bad.png)
GitHub - kylehickinson/SwiftUI-WebView: A SwiftUI component to use WKWebView
source link: https://github.com/kylehickinson/SwiftUI-WebView
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
WebView
A SwiftUI component View
that contains a WKWebView
Since WKWebView
handles a lot of its own state, navigation stack, etc, it's almost easier to treat it as a mutable data model. You can set it up prior to how you need it, and then simply use its data within your SwiftUI View's.
Simply spin up a WebViewStore
(optionally with your own WKWebView
) and use that to access the WKWebView
itself as if it was a data model.
Example usage:
import SwiftUI import WebView struct ContentView: View { @ObservedObject var webViewStore = WebViewStore() var body: some View { NavigationView { WebView(webView: webViewStore.webView) .navigationBarTitle(Text(verbatim: webViewStore.webView.title ?? ""), displayMode: .inline) .navigationBarItems(trailing: HStack { Button(action: goBack) { Image(systemName: "chevron.left") .imageScale(.large) .aspectRatio(contentMode: .fit) .frame(width: 32, height: 32) }.disabled(!webViewStore.webView.canGoBack) Button(action: goForward) { Image(systemName: "chevron.right") .imageScale(.large) .aspectRatio(contentMode: .fit) .frame(width: 32, height: 32) }.disabled(!webViewStore.webView.canGoForward) }) }.onAppear { self.webViewStore.webView.load(URLRequest(url: URL(string: "https://apple.com")!)) } } func goBack() { webViewStore.webView.goBack() } func goForward() { webViewStore.webView.goForward() } }
Recommend
-
167
website upgrading… 京ICP备110065...
-
75
website upgrading… 京ICP备110065...
-
50
说起 WKWebview 代替 UIWebview 带来的好处你可以举出一堆堆的例子,但说到 WKWebview 的问题,你绕不过的就是 WKWebview cookie 和 NSHTTPCookieStorage cookie 不共享的问题。你可以在网络上搜到如何将他们相互同步的帖子。 如何将 NSHTTPCookieStorage 同步给 W...
-
39
在iOS 8.0以后苹果推出WKWebView,之前有性能问题的UIWebView基本就被弃用了,这里整理下我的WKWebView之旅和怎么封装的。
-
26
最近项目中的UIWebView被替换为了WKWebView,因此来总结一下WKWebView的使用。 示例Demo:WKWebView的使用
-
58
WKWebView是iOS的重要部分,在任何时间地点都能提供高性能网络渲染。 在这篇文章里,我汇总了15条最常用的WKWebView案例,并提供了我验证过的代码解决方案。所以如果你...
-
48
iOS中的WKWebView使用简单方便。使用它你只用将你用到的进行封装。在你的ViewController中进行初始化WKWebView并加载和对其配置,就能完整的使用了。
-
22
On a recent app I worked on, there was a requirement for authentication within a WebView. For this to work custom request headers had to be sent through a Xamarin.Forms WebView. This is quite standard for a lot of hybrid web...
-
44
react-native-leaflet A LeafletView component using WebView and Leaflet map for React Native applications Notes: This project is replacement for https://github.c...
-
10
Webview UI Toolkit for Visual Studio Code Introduction The Webview UI Toolkit is a component library for building webview-based extensions in Visual St...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK