Skip to content

Commit 89658f6

Browse files
committed
Mark WebView as unavailable on tvOS
1 parent af6bde0 commit 89658f6

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

Sources/SwiftCrossUI/Views/WebView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22

3+
@available(tvOS, unavailable)
34
public struct WebView: ElementaryView {
45
@State var currentURL: URL?
56
@Binding var url: URL
Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,45 @@
1-
import SwiftCrossUI
2-
import WebKit
1+
#if !os(tvOS)
2+
import SwiftCrossUI
3+
import WebKit
34

4-
extension UIKitBackend {
5-
public func createWebView() -> Widget {
6-
WebViewWidget()
7-
}
5+
extension UIKitBackend {
6+
public func createWebView() -> Widget {
7+
WebViewWidget()
8+
}
89

9-
public func updateWebView(
10-
_ webView: Widget,
11-
environment: EnvironmentValues,
12-
onNavigate: @escaping (URL) -> Void
13-
) {
14-
let webView = webView as! WebViewWidget
15-
webView.onNavigate = onNavigate
16-
}
10+
public func updateWebView(
11+
_ webView: Widget,
12+
environment: EnvironmentValues,
13+
onNavigate: @escaping (URL) -> Void
14+
) {
15+
let webView = webView as! WebViewWidget
16+
webView.onNavigate = onNavigate
17+
}
1718

18-
public func navigateWebView(_ webView: Widget, to url: URL) {
19-
let webView = webView as! WebViewWidget
20-
let request = URLRequest(url: url)
21-
webView.child.load(request)
19+
public func navigateWebView(_ webView: Widget, to url: URL) {
20+
let webView = webView as! WebViewWidget
21+
let request = URLRequest(url: url)
22+
webView.child.load(request)
23+
}
2224
}
23-
}
2425

25-
/// A wrapper for WKWebView. Acts as the web view's delegate as well.
26-
final class WebViewWidget: WrapperWidget<WKWebView>, WKNavigationDelegate {
27-
var onNavigate: ((URL) -> Void)?
26+
/// A wrapper for WKWebView. Acts as the web view's delegate as well.
27+
final class WebViewWidget: WrapperWidget<WKWebView>, WKNavigationDelegate {
28+
var onNavigate: ((URL) -> Void)?
2829

29-
init() {
30-
super.init(child: WKWebView())
30+
init() {
31+
super.init(child: WKWebView())
3132

32-
child.navigationDelegate = self
33-
}
34-
35-
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
36-
guard let url = webView.url else {
37-
print("warning: Web view has no URL")
38-
return
33+
child.navigationDelegate = self
3934
}
4035

41-
onNavigate?(url)
36+
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
37+
guard let url = webView.url else {
38+
print("warning: Web view has no URL")
39+
return
40+
}
41+
42+
onNavigate?(url)
43+
}
4244
}
43-
}
45+
#endif

0 commit comments

Comments
 (0)