Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions iOS/Article/ImageScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ open class ImageScrollView: UIScrollView {

open func resize() {
self.configureImageForSize(self.imageSize)
self.adjustFrameToCenter()
}
}

Expand Down
12 changes: 9 additions & 3 deletions iOS/Article/ImageTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ final class ImageTransition: NSObject, UIViewControllerAnimatedTransitioning {
}

private func animateTransitionPresenting(using transitionContext: UIViewControllerContextTransitioning) {
guard let toViewController = transitionContext.viewController(forKey: .to),
let toView = transitionContext.view(forKey: .to) else {
transitionContext.completeTransition(false)
return
}

toView.frame = transitionContext.finalFrame(for: toViewController)
toView.layoutIfNeeded()

let imageView = UIImageView(image: originImage)
imageView.frame = originFrame
Expand All @@ -56,9 +64,7 @@ final class ImageTransition: NSObject, UIViewControllerAnimatedTransitioning {
}
}, completion: { _ in
imageView.removeFromSuperview()
if let toView = transitionContext.view(forKey: .to) {
transitionContext.containerView.addSubview(toView)
}
transitionContext.containerView.addSubview(toView)
transitionContext.completeTransition(true)
})
}
Expand Down
28 changes: 17 additions & 11 deletions iOS/Article/ImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ final class ImageViewController: UIViewController {
@IBOutlet var titleTrailing: NSLayoutConstraint!

private var shareButtonItem: UIBarButtonItem?
private var initialTitleConstraintConstants: (leading: CGFloat, trailing: CGFloat)?
private var lastImageScrollViewSize = CGSize.zero

var image: UIImage!
var imageTitle: String?
Expand Down Expand Up @@ -59,7 +61,7 @@ final class ImageViewController: UIViewController {
imageScrollView.display(image: image)

titleLabel.text = imageTitle ?? ""
layoutTitleLabel()
initialTitleConstraintConstants = (titleLeading.constant, titleTrailing.constant)

guard imageTitle != "" else {
titleBackground.removeFromSuperview()
Expand All @@ -68,11 +70,15 @@ final class ImageViewController: UIViewController {
titleBackground.layer.cornerRadius = 6
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: { [weak self] _ in
self?.imageScrollView.resize()
})
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
layoutTitleLabel()

let imageScrollViewSize = imageScrollView.bounds.size
if imageScrollViewSize != lastImageScrollViewSize {
lastImageScrollViewSize = imageScrollViewSize
imageScrollView.resize()
}
}

@IBAction func share(_ sender: Any) {
Expand All @@ -89,11 +95,11 @@ final class ImageViewController: UIViewController {
}

private func layoutTitleLabel() {
let width = view.frame.width
let multiplier = traitCollection.userInterfaceIdiom == .pad ? CGFloat(0.1) : CGFloat(0.04)
titleLeading.constant += width * multiplier
titleTrailing.constant -= width * multiplier
titleLabel.layoutIfNeeded()
guard let initialTitleConstraintConstants else { return }
let width = view.bounds.width
let multiplier = traitCollection.horizontalSizeClass == .regular ? CGFloat(0.1) : CGFloat(0.04)
titleLeading.constant = initialTitleConstraintConstants.leading + width * multiplier
titleTrailing.constant = initialTitleConstraintConstants.trailing - width * multiplier
}
}

Expand Down
2 changes: 1 addition & 1 deletion iOS/SceneCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ struct SidebarItemNode: Hashable, Sendable {
imageVC.imageTitle = imageTitle
imageVC.transition = transition
let navController = UINavigationController(rootViewController: imageVC)
navController.modalPresentationStyle = .currentContext
navController.modalPresentationStyle = .fullScreen
navController.transitioningDelegate = transition
rootSplitViewController.present(navController, animated: true)
}
Expand Down
Loading