From 60dd02cbcc06a1707cf6d669dc40f61a262b3991 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 5 Nov 2026 10:49:54 -0800 Subject: [PATCH] =?UTF-8?q?Restore=20current-context=20presentation=20for?= =?UTF-8?q?=20the=20full-screen=20image=20viewer.=20Resize=20image=20after?= =?UTF-8?q?=20scroll=20view=E2=80=99s=20layout=20to=20reduce=20jitter=20du?= =?UTF-8?q?ring=20rotation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iOS/Article/ImageScrollView.swift | 13 +++++++++++++ iOS/Article/ImageViewController.swift | 11 ----------- iOS/SceneCoordinator.swift | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/iOS/Article/ImageScrollView.swift b/iOS/Article/ImageScrollView.swift index eecd273d9..ec3c193a7 100644 --- a/iOS/Article/ImageScrollView.swift +++ b/iOS/Article/ImageScrollView.swift @@ -39,6 +39,7 @@ open class ImageScrollView: UIScrollView { var imageSize: CGSize = CGSize.zero private var pointToCenterAfterResize: CGPoint = CGPoint.zero private var scaleToRestoreAfterResize: CGFloat = 1.0 + private var lastLayoutSize = CGSize.zero var maxScaleFromMinScale: CGFloat = 3.0 var zoomedFrame: CGRect { @@ -71,6 +72,18 @@ open class ImageScrollView: UIScrollView { initialize() } + override open func layoutSubviews() { + super.layoutSubviews() + + // Resize after UIScrollView’s own layout, so that layout can’t move the image + // partway through a rotation animation. + guard imageSize != .zero, bounds.size != lastLayoutSize else { + return + } + lastLayoutSize = bounds.size + resize() + } + private func initialize() { showsVerticalScrollIndicator = false showsHorizontalScrollIndicator = false diff --git a/iOS/Article/ImageViewController.swift b/iOS/Article/ImageViewController.swift index c2d243037..a0290d47b 100644 --- a/iOS/Article/ImageViewController.swift +++ b/iOS/Article/ImageViewController.swift @@ -15,7 +15,6 @@ final class ImageViewController: UIViewController { @IBOutlet var titleLeading: NSLayoutConstraint! private var shareButtonItem: UIBarButtonItem? - private var lastImageScrollViewSize = CGSize.zero // Title margins as a fraction of the view width. private static let regularWidthTitleMarginMultiplier: CGFloat = 0.1 @@ -76,16 +75,6 @@ final class ImageViewController: UIViewController { layoutTitleLabel() } - override func viewDidLayoutSubviews() { - super.viewDidLayoutSubviews() - - let imageScrollViewSize = imageScrollView.bounds.size - if imageScrollViewSize != lastImageScrollViewSize { - lastImageScrollViewSize = imageScrollViewSize - imageScrollView.resize() - } - } - @IBAction func share(_ sender: Any) { guard let image else { return diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 93eb19461..017504798 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -1651,7 +1651,7 @@ struct SidebarItemNode: Hashable, Sendable { imageVC.imageTitle = imageTitle imageVC.transition = transition let navController = UINavigationController(rootViewController: imageVC) - navController.modalPresentationStyle = .fullScreen + navController.modalPresentationStyle = .currentContext navController.transitioningDelegate = transition rootSplitViewController.present(navController, animated: true) }