From df8b404e1dc96756d43ec4bb4c3924686f76f4e9 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 5 Dec 2024 22:06:00 -0800 Subject: [PATCH] =?UTF-8?q?Present=20SFSafariViewController=20using=20.ove?= =?UTF-8?q?rFullScreen=20instead=20of=20default=20.fullScreen=20=E2=80=94?= =?UTF-8?q?=20avoids=20a=20crash=20in=20-[UINavigationBar=20layoutSubviews?= =?UTF-8?q?].=20Fix=20#4418.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iOS/Article/WebViewController.swift | 15 +++++++++------ iOS/MasterFeed/MasterFeedViewController.swift | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index e48dd3471..7591da1b2 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -273,8 +273,7 @@ class WebViewController: UIViewController { if AppDefaults.shared.useSystemBrowser { UIApplication.shared.open(url, options: [:]) } else { - let vc = SFSafariViewController(url: url) - present(vc, animated: true) + openURLInSafariViewController(url) } } } @@ -378,8 +377,7 @@ extension WebViewController: WKNavigationDelegate { guard didOpen == false else { return } - let vc = SFSafariViewController(url: url) - self.present(vc, animated: true) + self.openURLInSafariViewController(url) } } @@ -794,11 +792,16 @@ private extension WebViewController { guard didOpen == false else { return } - let vc = SFSafariViewController(url: url) - self.present(vc, animated: true) + self.openURLInSafariViewController(url) } } + func openURLInSafariViewController(_ url: URL) { + + let viewController = SFSafariViewController(url: url) + viewController.modalPresentationStyle = .overFullScreen // This avoids a crash with .fullScreen + present(viewController, animated: true) + } } // MARK: Find in Article diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index a64c160e9..185f72faf 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -676,6 +676,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { if let indexPath = coordinator.currentFeedIndexPath, let url = coordinator.homePageURLForFeed(indexPath) { let vc = SFSafariViewController(url: url) + vc.modalPresentationStyle = .overFullScreen present(vc, animated: true) } }