Skip to content

Commit

Permalink
Merge pull request openedx#31 from edx/about-blank-links-fix
Browse files Browse the repository at this point in the history
fix: open link in Safari if link has target blank
  • Loading branch information
forgotvas authored Jul 22, 2024
2 parents 28fd8d3 + da26a8e commit ce09261
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Core/Core/View/Base/Webview/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,23 @@ public struct WebView: UIViewRepresentable {
}

let baseURL = await parent.viewModel.baseURL
if !baseURL.isEmpty, !url.absoluteString.starts(with: baseURL) {
if navigationAction.navigationType == .other {
return .allow
} else if navigationAction.navigationType == .linkActivated {
await MainActor.run {
switch navigationAction.navigationType {
case .other, .formSubmitted, .formResubmitted:
return .allow
case .linkActivated:
await MainActor.run {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:])
}
} else if navigationAction.navigationType == .formSubmitted {
return .allow
}
return .cancel
default:
if !baseURL.isEmpty, !url.absoluteString.starts(with: baseURL) {
return .cancel
} else {
return .allow
}
}

return .allow
}

public func webView(
Expand Down

0 comments on commit ce09261

Please sign in to comment.