Skip to content

Commit

Permalink
refactor(mobile): replace custom web view with SFSafariViewController
Browse files Browse the repository at this point in the history
This change updates the web view presentation logic to use SFSafariViewController instead of custom modal web view controllers. The modification simplifies the web view handling and provides a more standard iOS browsing experience with built-in Safari features.

Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Feb 28, 2025
1 parent cd576ff commit 7de1132
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ class ModalWebViewController: UIViewController {
}

override func viewDidLoad() {
super.viewDidLoad()
super.viewDidLoad()
if let navVC = self.navigationController {
let bar = navVC.navigationBar
self.webView.scrollView.contentInset.top = bar.frame.height - view.safeAreaInsets.top
}

setupNavigationBar()
setupWebView()
Expand Down Expand Up @@ -64,8 +68,7 @@ class ModalWebViewController: UIViewController {
view.addSubview(webView)
view.backgroundColor = .systemBackground
webView.snp.makeConstraints { make in
make.top.equalTo(view.safeAreaLayoutGuide)
make.left.right.bottom.equalToSuperview()
make.edges.equalToSuperview()
}
}

Expand Down
9 changes: 0 additions & 9 deletions apps/mobile/native/ios/Helper/HelperModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ public class HelperModule: Module {
return
}
DispatchQueue.main.async {
//
// if let navVC = UIWindow.findRNSNavigationController() as? UINavigationController {
// debugPrint(navVC)
//
// navVC.pushViewController(WebViewController(url: url), animated: true)
//// WebViewManager.pushModalWebView(url: url, from: navVC)
//
// }

guard let rootVC = UIApplication.shared.windows.first?.rootViewController else { return }
WebViewManager.presentModalWebView(url: url, from: rootVC)
}
Expand Down
15 changes: 7 additions & 8 deletions apps/mobile/native/ios/SharedWebView/WebViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//
import Combine
import ExpoModulesCore
import SafariServices

@preconcurrency import WebKit

private var pendingJavaScripts: [String] = []
Expand Down Expand Up @@ -170,16 +172,13 @@ enum WebViewManager {
}

static func presentModalWebView(url: URL, from viewController: UIViewController) {
let modalVC = ModalWebViewController(url: url)
let navController = UINavigationController(rootViewController: modalVC)
navController.modalPresentationStyle = .fullScreen
viewController.present(navController, animated: true)
}

static func pushModalWebView(url: URL, from navigationController: UINavigationController) {
let modalVC = WebViewController(url: url)
navigationController.pushViewController(modalVC, animated: true)
let safariVC = SFSafariViewController(url: url)
safariVC.view.tintColor = Utils.accentColor
safariVC.preferredControlTintColor = Utils.accentColor
viewController.present(safariVC, animated: true)
}

}

private class WebViewDelegate: NSObject, WKNavigationDelegate, WKScriptMessageHandler, WKUIDelegate
Expand Down

0 comments on commit 7de1132

Please sign in to comment.