Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loop caused by URL loading #1

Merged
merged 5 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/WebUI/WebView+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ extension WebView: View {
@MainActor
private func makeEnhancedWKWebView() -> EnhancedWKWebView {
let webView = EnhancedWKWebView(frame: .zero, configuration: parent.configuration)
parent.applyModifiers(to: webView)
proxy.setUp(webView)
parent.applyModifiers(to: webView)
parent.loadInitialURL(in: webView)
return webView
}

Expand Down
12 changes: 8 additions & 4 deletions Sources/WebUI/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import WebKit
public struct WebView {
let configuration: WKWebViewConfiguration

private let url: URL?
private let initialURL: URL?

private var uiDelegate: (any WKUIDelegate)?
private var navigationDelegate: (any WKNavigationDelegate)?
Expand All @@ -29,7 +29,7 @@ public struct WebView {
/// - url: The initial URL to load.
/// - configuration: The configuration for the new web view.
public init(url: URL? = nil, configuration: WKWebViewConfiguration = .init()) {
self.url = url
self.initialURL = url
self.configuration = configuration
}

Expand Down Expand Up @@ -106,8 +106,12 @@ public struct WebView {
webView.allowsBackForwardNavigationGestures = allowsBackForwardNavigationGestures
webView.allowsLinkPreview = allowsLinkPreview
webView.isRefreshable = isRefreshable
if let url {
webView.load(URLRequest(url: url))
}

@MainActor
func loadInitialURL(in webView: EnhancedWKWebView) {
if let initialURL {
webView.load(URLRequest(url: initialURL))
}
}
}
Loading