forked from shadowfacts/Tusker
93 lines
2.3 KiB
Swift
93 lines
2.3 KiB
Swift
//
|
|
// FallbackGalleryContentViewController.swift
|
|
// GalleryVC
|
|
//
|
|
// Created by Shadowfacts on 3/18/24.
|
|
// Copyright © 2024 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import QuickLook
|
|
|
|
private class FallbackGalleryContentViewController: QLPreviewController {
|
|
private let previewItem = GalleryPreviewItem()
|
|
|
|
init(url: URL) {
|
|
super.init(nibName: nil, bundle: nil)
|
|
|
|
self.previewItem.previewItemURL = url
|
|
|
|
dataSource = self
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
overrideUserInterfaceStyle = .dark
|
|
|
|
navigationItem.rightBarButtonItems = [
|
|
UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(closePressed))
|
|
]
|
|
}
|
|
|
|
@objc private func closePressed() {
|
|
self.dismiss(animated: true)
|
|
}
|
|
|
|
}
|
|
|
|
extension FallbackGalleryContentViewController: QLPreviewControllerDataSource {
|
|
func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
|
|
1
|
|
}
|
|
|
|
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> any QLPreviewItem {
|
|
previewItem
|
|
}
|
|
}
|
|
|
|
public class FallbackGalleryNavigationController: UINavigationController, GalleryContentViewController {
|
|
public init(url: URL) {
|
|
super.init(nibName: nil, bundle: nil)
|
|
self.viewControllers = [FallbackGalleryContentViewController(url: url)]
|
|
}
|
|
|
|
public override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
container?.disableGalleryScrollAndZoom()
|
|
}
|
|
|
|
public required init?(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
// MARK: GalleryContentViewController
|
|
|
|
public weak var container: (any GalleryContentViewControllerContainer)?
|
|
|
|
public var contentSize: CGSize {
|
|
.zero
|
|
}
|
|
|
|
public var activityItemsForSharing: [Any] {
|
|
[]
|
|
}
|
|
|
|
public var caption: String? {
|
|
nil
|
|
}
|
|
|
|
public var presentationAnimation: GalleryContentPresentationAnimation {
|
|
.fade
|
|
}
|
|
}
|
|
|
|
private class GalleryPreviewItem: NSObject, QLPreviewItem {
|
|
var previewItemURL: URL? = nil
|
|
}
|