Use LoadingLargeImageViewController for account avatar/header

Prevents crash when tapping unloaded avatar/header images
This commit is contained in:
Shadowfacts 2020-03-17 21:42:09 -04:00
parent 3bbbb05083
commit 5e9caf9179
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 40 additions and 6 deletions

View File

@ -7,8 +7,6 @@
//
import UIKit
import Pachyderm
import Photos
import Gifu
class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeImageAnimatableViewController {

View File

@ -8,8 +8,8 @@
import UIKit
import Pachyderm
class LoadingLargeImageViewController: UIViewController {
class LoadingLargeImageViewController: UIViewController, LargeImageAnimatableViewController {
let url: URL
let cache: ImageCache
let imageDescription: String?
@ -33,9 +33,24 @@ class LoadingLargeImageViewController: UIViewController {
}
}
var animationSourceInfo: LargeImageViewController.SourceInfo?
var animationImage: UIImage? { animationSourceInfo?.image ?? largeImageVC?.image }
var animationGifData: Data? { largeImageVC?.gifData }
var dismissInteractionController: LargeImageInteractionController?
override var prefersStatusBarHidden: Bool {
return true
}
override var childForHomeIndicatorAutoHidden: UIViewController? {
return largeImageVC
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
if UIDevice.current.userInterfaceIdiom == .phone {
return .allButUpsideDown
} else {
return .all
}
}
init(url: URL, cache: ImageCache, imageDescription: String?) {
self.url = url
@ -43,6 +58,8 @@ class LoadingLargeImageViewController: UIViewController {
self.imageDescription = imageDescription
super.init(nibName: nil, bundle: nil)
modalPresentationStyle = .fullScreen
}
convenience init(attachment: Attachment) {
@ -73,6 +90,8 @@ class LoadingLargeImageViewController: UIViewController {
}
}
}
dismissInteractionController = LargeImageInteractionController(viewController: self)
}
override func didMove(toParent parent: UIViewController?) {

View File

@ -44,6 +44,10 @@ protocol TuskerNavigationDelegate: class {
func showLargeImage(gifData: Data, description: String?, animatingFrom sourceView: UIImageView)
func loadingLargeImage(url: URL, cache: ImageCache, description: String?, animatingFrom sourceView: UIImageView) -> LoadingLargeImageViewController
func showLoadingLargeImage(url: URL, cache: ImageCache, description: String?, animatingFrom sourceView: UIImageView)
func gallery(attachments: [Attachment], sourceViews: [UIImageView?], startIndex: Int) -> GalleryViewController
func showGallery(attachments: [Attachment], sourceViews: [UIImageView?], startIndex: Int)
@ -183,6 +187,17 @@ extension TuskerNavigationDelegate where Self: UIViewController {
present(largeImage(gifData: gifData, description: description, sourceView: sourceView), animated: true)
}
func loadingLargeImage(url: URL, cache: ImageCache, description: String?, animatingFrom sourceView: UIImageView) -> LoadingLargeImageViewController {
let vc = LoadingLargeImageViewController(url: url, cache: cache, imageDescription: description)
vc.animationSourceInfo = sourceViewInfo(sourceView)
vc.transitioningDelegate = self
return vc
}
func showLoadingLargeImage(url: URL, cache: ImageCache, description: String?, animatingFrom sourceView: UIImageView) {
present(loadingLargeImage(url: url, cache: cache, description: description, animatingFrom: sourceView), animated: true)
}
func gallery(attachments: [Attachment], sourceViews: [UIImageView?], startIndex: Int) -> GalleryViewController {
let sourcesInfo = sourceViews.map(sourceViewInfo)
let vc = GalleryViewController(attachments: attachments, sourcesInfo: sourcesInfo, startIndex: startIndex)

View File

@ -149,11 +149,13 @@ class ProfileHeaderTableViewCell: UITableViewCell {
}
@objc func avatarPressed() {
delegate?.showLargeImage(avatarImageView.image!, description: nil, animatingFrom: avatarImageView)
guard let account = mastodonController.cache.account(for: accountID) else { fatalError("Missing cached account \(accountID!)") }
delegate?.showLoadingLargeImage(url: account.avatar, cache: .avatars, description: nil, animatingFrom: avatarImageView)
}
@objc func headerPressed() {
delegate?.showLargeImage(headerImageView.image!, description: nil, animatingFrom: headerImageView)
guard let account = mastodonController.cache.account(for: accountID) else { fatalError("Missing cached account \(accountID!)") }
delegate?.showLoadingLargeImage(url: account.header, cache: .headers, description: nil, animatingFrom: headerImageView)
}
}