73 lines
2.2 KiB
Swift
73 lines
2.2 KiB
Swift
//
|
|
// GifvGalleryContentViewController.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 3/18/24.
|
|
// Copyright © 2024 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import GalleryVC
|
|
import Combine
|
|
|
|
class GifvGalleryContentViewController: UIViewController, GalleryContentViewController {
|
|
private let controller: GifvController
|
|
private let url: URL
|
|
let caption: String?
|
|
|
|
private var presentationSizeCancellable: AnyCancellable?
|
|
|
|
init(controller: GifvController, url: URL, caption: String?) {
|
|
self.controller = controller
|
|
self.url = url
|
|
self.caption = caption
|
|
|
|
super.init(nibName: nil, bundle: nil)
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
let playerView = GifvPlayerView(controller: controller, gravity: .resizeAspect)
|
|
playerView.translatesAutoresizingMaskIntoConstraints = false
|
|
view.addSubview(playerView)
|
|
NSLayoutConstraint.activate([
|
|
playerView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
playerView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
|
playerView.topAnchor.constraint(equalTo: view.topAnchor),
|
|
playerView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
|
])
|
|
|
|
presentationSizeCancellable = controller.presentationSizeSubject
|
|
.sink { [unowned self] size in
|
|
self.preferredContentSize = size
|
|
self.container?.galleryContentChanged()
|
|
}
|
|
|
|
preferredContentSize = controller.item.presentationSize
|
|
}
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
|
|
controller.play()
|
|
}
|
|
|
|
// MARK: GalleryContentViewController
|
|
|
|
var container: (any GalleryVC.GalleryContentViewControllerContainer)?
|
|
|
|
var contentSize: CGSize {
|
|
controller.item.presentationSize
|
|
}
|
|
|
|
var activityItemsForSharing: [Any] {
|
|
[VideoActivityItemSource(asset: controller.item.asset, url: url)]
|
|
}
|
|
|
|
}
|