Put image view in navigation controller so that close and share buttons are laid out properly (ignoring iPad traffic lights). Fixes #5260.

This commit is contained in:
Brent Simmons committed 2026-05-27 11:38:09 -07:00
1 parent 8c02fb3ba4
commit 98b05ca283
4 files changed
+33 -50

No files matched your search

+12 -3
View File
@@ -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
}
}
+17 -8
View File
@@ -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)
}
-36
View File
@@ -741,41 +741,10 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="RmY-a3-hUg">
<rect key="frame" x="350" y="124" width="44" height="44"/>
<constraints>
<constraint firstAttribute="width" constant="44" id="56o-Zr-T0w"/>
<constraint firstAttribute="height" constant="44" id="lBg-Wy-k9P"/>
</constraints>
<color key="tintColor" name="primaryAccentColor"/>
<state key="normal" image="square.and.arrow.up.fill" catalog="system"/>
<buttonConfiguration key="configuration" style="tinted" image="square.and.arrow.up" catalog="system" cornerStyle="capsule"/>
<connections>
<action selector="share:" destination="vO9-a3-Dnu" eventType="touchUpInside" id="m8y-Gs-YF1"/>
</connections>
</button>
<button opaque="NO" clipsSubviews="YES" contentMode="center" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cXR-ll-xBx">
<rect key="frame" x="8" y="124" width="44" height="44"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="6kc-Gw-KbZ"/>
<constraint firstAttribute="width" constant="44" id="cBq-gs-WzN"/>
</constraints>
<color key="tintColor" name="primaryAccentColor"/>
<state key="normal" image="multiply.circle.fill" catalog="system">
<preferredSymbolConfiguration key="preferredSymbolConfiguration" scale="large" weight="regular"/>
</state>
<buttonConfiguration key="configuration" style="tinted" image="multiply.circle" catalog="system" cornerStyle="capsule">
<preferredSymbolConfiguration key="preferredSymbolConfigurationForImage" scale="large" weight="regular"/>
</buttonConfiguration>
<connections>
<action selector="done:" destination="vO9-a3-Dnu" eventType="touchUpInside" id="tgd-ov-4Ft"/>
</connections>
</button>
</subviews>
<viewLayoutGuide key="safeArea" id="mbY-02-GFL"/>
<color key="backgroundColor" name="fullScreenBackgroundColor"/>
<constraints>
<constraint firstItem="RmY-a3-hUg" firstAttribute="top" secondItem="mbY-02-GFL" secondAttribute="top" id="A0i-Hs-1Ac"/>
<constraint firstAttribute="bottom" secondItem="msG-pz-EKk" secondAttribute="bottom" id="AtA-bA-jDr"/>
<constraint firstItem="eMj-1g-3xm" firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="mbY-02-GFL" secondAttribute="trailing" id="E7e-Lv-6ZA"/>
<constraint firstItem="eMj-1g-3xm" firstAttribute="centerX" secondItem="w6Q-vH-063" secondAttribute="centerX" id="H2b-IA-6hz"/>
@@ -783,20 +752,15 @@
<constraint firstAttribute="trailing" secondItem="msG-pz-EKk" secondAttribute="trailing" id="R49-qV-8nm"/>
<constraint firstItem="msG-pz-EKk" firstAttribute="leading" secondItem="w6Q-vH-063" secondAttribute="leading" id="XN1-xN-hYS"/>
<constraint firstItem="eMj-1g-3xm" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="mbY-02-GFL" secondAttribute="leading" id="Xni-Dn-I3Z"/>
<constraint firstItem="mbY-02-GFL" firstAttribute="trailing" secondItem="RmY-a3-hUg" secondAttribute="trailing" constant="8" id="Zlz-lM-LV8"/>
<constraint firstItem="mbY-02-GFL" firstAttribute="bottom" secondItem="eMj-1g-3xm" secondAttribute="bottom" constant="8" id="eaS-iG-yMv"/>
<constraint firstItem="bHh-pW-oTS" firstAttribute="leading" secondItem="eMj-1g-3xm" secondAttribute="leading" constant="-4" id="f8r-dq-Irr"/>
<constraint firstItem="bHh-pW-oTS" firstAttribute="top" secondItem="eMj-1g-3xm" secondAttribute="top" constant="-4" id="gTP-i5-FYQ"/>
<constraint firstItem="msG-pz-EKk" firstAttribute="top" secondItem="w6Q-vH-063" secondAttribute="top" id="p1a-s0-wdK"/>
<constraint firstItem="bHh-pW-oTS" firstAttribute="trailing" secondItem="eMj-1g-3xm" secondAttribute="trailing" constant="4" id="qB9-zk-5JN"/>
<constraint firstItem="cXR-ll-xBx" firstAttribute="leading" secondItem="mbY-02-GFL" secondAttribute="leading" constant="8" id="vJs-LN-Ydd"/>
<constraint firstItem="cXR-ll-xBx" firstAttribute="top" secondItem="mbY-02-GFL" secondAttribute="top" id="xVN-Qt-WYA"/>
</constraints>
</view>
<connections>
<outlet property="closeButton" destination="cXR-ll-xBx" id="sDG-49-joi"/>
<outlet property="imageScrollView" destination="msG-pz-EKk" id="dGi-M6-dcO"/>
<outlet property="shareButton" destination="RmY-a3-hUg" id="Z54-ah-WAI"/>
<outlet property="titleBackground" destination="bHh-pW-oTS" id="o2K-cY-90c"/>
<outlet property="titleLabel" destination="eMj-1g-3xm" id="6wF-IZ-fNw"/>
<outlet property="titleLeading" destination="Xni-Dn-I3Z" id="8Ik-la-Qkw"/>
+4 -3
View File
@@ -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? {