diff --git a/iOS/Article/ImageTransition.swift b/iOS/Article/ImageTransition.swift index 941af5459..3ea1cea1d 100644 --- a/iOS/Article/ImageTransition.swift +++ b/iOS/Article/ImageTransition.swift @@ -52,8 +52,9 @@ final class ImageTransition: NSObject, UIViewControllerAnimatedTransitioning { usingSpringWithDamping: 0.8, initialSpringVelocity: 0.2, animations: { - let imageController = transitionContext.viewController(forKey: .to) as! ImageViewController - imageView.frame = imageController.zoomedFrame + if let imageController = self.imageViewController(forKey: .to, in: transitionContext) { + imageView.frame = imageController.zoomedFrame + } }, completion: { _ in imageView.removeFromSuperview() let toView = transitionContext.view(forKey: .to)! @@ -63,7 +64,10 @@ final class ImageTransition: NSObject, UIViewControllerAnimatedTransitioning { } private func animateTransitionReturning(using transitionContext: UIViewControllerContextTransitioning) { - let imageController = transitionContext.viewController(forKey: .from) as! ImageViewController + guard let imageController = imageViewController(forKey: .from, in: transitionContext) else { + transitionContext.completeTransition(false) + return + } let imageView = UIImageView(image: originImage) imageView.frame = imageController.zoomedFrame @@ -107,4 +111,9 @@ final class ImageTransition: NSObject, UIViewControllerAnimatedTransitioning { }) } + private func imageViewController(forKey key: UITransitionContextViewControllerKey, in context: UIViewControllerContextTransitioning) -> ImageViewController? { + let navigationController = context.viewController(forKey: key) as? UINavigationController + return navigationController?.viewControllers.first as? ImageViewController + } + } diff --git a/iOS/Article/ImageViewController.swift b/iOS/Article/ImageViewController.swift index 1d4ad685d..3d84c6ece 100644 --- a/iOS/Article/ImageViewController.swift +++ b/iOS/Article/ImageViewController.swift @@ -9,14 +9,14 @@ import UIKit final class ImageViewController: UIViewController { - @IBOutlet var closeButton: UIButton! - @IBOutlet var shareButton: UIButton! @IBOutlet var imageScrollView: ImageScrollView! @IBOutlet var titleLabel: UILabel! @IBOutlet var titleBackground: UIVisualEffectView! @IBOutlet var titleLeading: NSLayoutConstraint! @IBOutlet var titleTrailing: NSLayoutConstraint! + private var shareButtonItem: UIBarButtonItem? + var image: UIImage! var imageTitle: String? var zoomedFrame: CGRect { @@ -36,11 +36,19 @@ final class ImageViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - closeButton.imageView?.contentMode = .scaleAspectFit - closeButton.accessibilityLabel = NSLocalizedString("Close", comment: "Close") - shareButton.accessibilityLabel = NSLocalizedString("Share", comment: "Share") + let closeButtonItem = UIBarButtonItem(barButtonSystemItem: .close, target: self, action: #selector(done(_:))) + closeButtonItem.tintColor = Assets.Colors.primaryAccent + let shareButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(share(_:))) + shareButtonItem.tintColor = Assets.Colors.primaryAccent + navigationItem.leftBarButtonItem = closeButtonItem + navigationItem.rightBarButtonItem = shareButtonItem + self.shareButtonItem = shareButtonItem imageScrollView.setup() + // The image viewer is full-screen, so the scroll view ignores + // the navigation bar and safe area insets. Otherwise the image is pushed down + // and doesn’t match the zoom transition’s target frame. + imageScrollView.contentInsetAdjustmentBehavior = .never imageScrollView.imageScrollViewDelegate = self imageScrollView.imageContentMode = .aspectFit imageScrollView.initialOffset = .center @@ -64,10 +72,11 @@ final class ImageViewController: UIViewController { } @IBAction func share(_ sender: Any) { - guard let image = image else { return } + guard let image else { + return + } let activityViewController = UIActivityViewController(activityItems: [image], applicationActivities: nil) - activityViewController.popoverPresentationController?.sourceView = shareButton - activityViewController.popoverPresentationController?.sourceRect = shareButton.bounds + activityViewController.popoverPresentationController?.barButtonItem = shareButtonItem present(activityViewController, animated: true) } diff --git a/iOS/Base.lproj/Main.storyboard b/iOS/Base.lproj/Main.storyboard index 237dc76e3..949061a9d 100644 --- a/iOS/Base.lproj/Main.storyboard +++ b/iOS/Base.lproj/Main.storyboard @@ -741,41 +741,10 @@ - - - @@ -783,20 +752,15 @@ - - - - - diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index e9b5997df..f542f10d7 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -1420,9 +1420,10 @@ struct SidebarItemNode: Hashable, Sendable { let imageVC = UIStoryboard.main.instantiateController(ofType: ImageViewController.self) imageVC.image = image imageVC.imageTitle = imageTitle - imageVC.modalPresentationStyle = .currentContext - imageVC.transitioningDelegate = transitioningDelegate - rootSplitViewController.present(imageVC, animated: true) + let navController = UINavigationController(rootViewController: imageVC) + navController.modalPresentationStyle = .currentContext + navController.transitioningDelegate = transitioningDelegate + rootSplitViewController.present(navController, animated: true) } func homePageURLForFeed(_ indexPath: IndexPath) -> URL? {