mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-30 01:10:38 +00:00
Fix blank UI after dismissing a full-screen image. Fixes #3641.
This commit is contained in:
1 parent
74eea8fe86
commit
bec611c1fc
4 files changed
+44
-26
No files matched your search
@@ -38,8 +38,7 @@ final class ImageTransition: NSObject, UIViewControllerAnimatedTransitioning {
|
||||
let imageView = UIImageView(image: originImage)
|
||||
imageView.frame = originFrame
|
||||
|
||||
let fromView = transitionContext.view(forKey: .from)!
|
||||
fromView.removeFromSuperview()
|
||||
transitionContext.view(forKey: .from)?.removeFromSuperview()
|
||||
|
||||
transitionContext.containerView.backgroundColor = Assets.Colors.fullScreenBackground
|
||||
transitionContext.containerView.addSubview(imageView)
|
||||
@@ -57,25 +56,36 @@ final class ImageTransition: NSObject, UIViewControllerAnimatedTransitioning {
|
||||
}
|
||||
}, completion: { _ in
|
||||
imageView.removeFromSuperview()
|
||||
let toView = transitionContext.view(forKey: .to)!
|
||||
transitionContext.containerView.addSubview(toView)
|
||||
if let toView = transitionContext.view(forKey: .to) {
|
||||
transitionContext.containerView.addSubview(toView)
|
||||
}
|
||||
transitionContext.completeTransition(true)
|
||||
})
|
||||
}
|
||||
|
||||
private func animateTransitionReturning(using transitionContext: UIViewControllerContextTransitioning) {
|
||||
guard let imageController = imageViewController(forKey: .from, in: transitionContext) else {
|
||||
|
||||
// The presenting animation removed the destination view from the window,
|
||||
// so it must be restored on every path out of here.
|
||||
guard let toView = transitionContext.view(forKey: .to) else {
|
||||
transitionContext.completeTransition(false)
|
||||
return
|
||||
}
|
||||
|
||||
guard let imageController = imageViewController(forKey: .from, in: transitionContext),
|
||||
let fromView = transitionContext.view(forKey: .from),
|
||||
let window = fromView.window else {
|
||||
transitionContext.containerView.addSubview(toView)
|
||||
transitionContext.completeTransition(true)
|
||||
return
|
||||
}
|
||||
|
||||
let imageView = UIImageView(image: originImage)
|
||||
imageView.frame = imageController.zoomedFrame
|
||||
|
||||
let fromView = transitionContext.view(forKey: .from)!
|
||||
let windowFrame = fromView.window!.frame
|
||||
let windowFrame = window.frame
|
||||
fromView.removeFromSuperview()
|
||||
|
||||
let toView = transitionContext.view(forKey: .to)!
|
||||
transitionContext.containerView.addSubview(toView)
|
||||
|
||||
let maskingView = UIView()
|
||||
@@ -117,3 +127,21 @@ final class ImageTransition: NSObject, UIViewControllerAnimatedTransitioning {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// The transition is its own transitioning delegate, strongly owned by the presented
|
||||
// ImageViewController — the WebViewController that configured it can be deallocated
|
||||
// while the viewer is up, and the dismissal animation must still run to restore the
|
||||
// view the presenting animation removed.
|
||||
// <https://github.com/Ranchero-Software/NetNewsWire/issues/3641>
|
||||
extension ImageTransition: UIViewControllerTransitioningDelegate {
|
||||
|
||||
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
||||
self.presenting = true
|
||||
return self
|
||||
}
|
||||
|
||||
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
||||
self.presenting = false
|
||||
return self
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,10 @@ final class ImageViewController: UIViewController {
|
||||
|
||||
var image: UIImage!
|
||||
var imageTitle: String?
|
||||
|
||||
// Strong reference — the navigation controller’s transitioningDelegate is weak,
|
||||
// and the transition must outlive the WebViewController that configured it.
|
||||
var transition: ImageTransition?
|
||||
var zoomedFrame: CGRect {
|
||||
return imageScrollView.zoomedFrame
|
||||
}
|
||||
|
||||
@@ -505,21 +505,6 @@ extension WebViewController: WKScriptMessageHandler {
|
||||
|
||||
}
|
||||
|
||||
// MARK: UIViewControllerTransitioningDelegate
|
||||
|
||||
extension WebViewController: UIViewControllerTransitioningDelegate {
|
||||
|
||||
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
||||
transition.presenting = true
|
||||
return transition
|
||||
}
|
||||
|
||||
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
||||
transition.presenting = false
|
||||
return transition
|
||||
}
|
||||
}
|
||||
|
||||
// MARK:
|
||||
|
||||
extension WebViewController: UIScrollViewDelegate {
|
||||
@@ -726,7 +711,7 @@ private extension WebViewController {
|
||||
|
||||
transition.originImage = image
|
||||
|
||||
coordinator.showFullScreenImage(image: image, imageTitle: clickMessage.imageTitle, transitioningDelegate: self)
|
||||
coordinator.showFullScreenImage(image: image, imageTitle: clickMessage.imageTitle, transition: transition)
|
||||
}
|
||||
|
||||
func stopMediaPlayback(_ webView: WKWebView) {
|
||||
|
||||
@@ -1486,13 +1486,14 @@ struct SidebarItemNode: Hashable, Sendable {
|
||||
mainFeedCollectionViewController.present(addNavViewController, animated: true)
|
||||
}
|
||||
|
||||
func showFullScreenImage(image: UIImage, imageTitle: String?, transitioningDelegate: UIViewControllerTransitioningDelegate) {
|
||||
func showFullScreenImage(image: UIImage, imageTitle: String?, transition: ImageTransition) {
|
||||
let imageVC = UIStoryboard.main.instantiateController(ofType: ImageViewController.self)
|
||||
imageVC.image = image
|
||||
imageVC.imageTitle = imageTitle
|
||||
imageVC.transition = transition
|
||||
let navController = UINavigationController(rootViewController: imageVC)
|
||||
navController.modalPresentationStyle = .currentContext
|
||||
navController.transitioningDelegate = transitioningDelegate
|
||||
navController.transitioningDelegate = transition
|
||||
rootSplitViewController.present(navController, animated: true)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user