forked from shadowfacts/Tusker
parent
cf71fc3f98
commit
a80cbe79c2
|
@ -15,6 +15,8 @@ public protocol GalleryContentViewController: UIViewController {
|
||||||
var caption: String? { get }
|
var caption: String? { get }
|
||||||
var bottomControlsAccessoryViewController: UIViewController? { get }
|
var bottomControlsAccessoryViewController: UIViewController? { get }
|
||||||
var canAnimateFromSourceView: Bool { get }
|
var canAnimateFromSourceView: Bool { get }
|
||||||
|
|
||||||
|
func setControlsVisible(_ visible: Bool, animated: Bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension GalleryContentViewController {
|
public extension GalleryContentViewController {
|
||||||
|
@ -25,4 +27,7 @@ public extension GalleryContentViewController {
|
||||||
var canAnimateFromSourceView: Bool {
|
var canAnimateFromSourceView: Bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setControlsVisible(_ visible: Bool, animated: Bool) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ import Foundation
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
public protocol GalleryContentViewControllerContainer {
|
public protocol GalleryContentViewControllerContainer {
|
||||||
|
var galleryControlsVisible: Bool { get }
|
||||||
|
|
||||||
func setGalleryContentLoading(_ loading: Bool)
|
func setGalleryContentLoading(_ loading: Bool)
|
||||||
func galleryContentChanged()
|
func galleryContentChanged()
|
||||||
func disableGalleryScrollAndZoom()
|
func disableGalleryScrollAndZoom()
|
||||||
|
|
|
@ -192,6 +192,8 @@ class GalleryItemViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
func addContent() {
|
func addContent() {
|
||||||
|
content.setControlsVisible(controlsVisible, animated: false)
|
||||||
|
|
||||||
content.view.translatesAutoresizingMaskIntoConstraints = false
|
content.view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
if content.parent != self {
|
if content.parent != self {
|
||||||
addChild(content)
|
addChild(content)
|
||||||
|
@ -229,6 +231,7 @@ class GalleryItemViewController: UIViewController {
|
||||||
func updateControlsViews() {
|
func updateControlsViews() {
|
||||||
topControlsView.transform = CGAffineTransform(translationX: 0, y: visible ? 0 : -topControlsView.bounds.height)
|
topControlsView.transform = CGAffineTransform(translationX: 0, y: visible ? 0 : -topControlsView.bounds.height)
|
||||||
bottomControlsView.transform = CGAffineTransform(translationX: 0, y: visible ? 0 : bottomControlsView.bounds.height)
|
bottomControlsView.transform = CGAffineTransform(translationX: 0, y: visible ? 0 : bottomControlsView.bounds.height)
|
||||||
|
content.setControlsVisible(visible, animated: animated)
|
||||||
}
|
}
|
||||||
if animated {
|
if animated {
|
||||||
let animator = UIViewPropertyAnimator(duration: 0.2, timingParameters: UISpringTimingParameters())
|
let animator = UIViewPropertyAnimator(duration: 0.2, timingParameters: UISpringTimingParameters())
|
||||||
|
@ -396,6 +399,10 @@ class GalleryItemViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension GalleryItemViewController: GalleryContentViewControllerContainer {
|
extension GalleryItemViewController: GalleryContentViewControllerContainer {
|
||||||
|
var galleryControlsVisible: Bool {
|
||||||
|
controlsVisible
|
||||||
|
}
|
||||||
|
|
||||||
func setGalleryContentLoading(_ loading: Bool) {
|
func setGalleryContentLoading(_ loading: Bool) {
|
||||||
if loading {
|
if loading {
|
||||||
if activityIndicator == nil {
|
if activityIndicator == nil {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import UIKit
|
||||||
import GalleryVC
|
import GalleryVC
|
||||||
import Pachyderm
|
import Pachyderm
|
||||||
import TuskerComponents
|
import TuskerComponents
|
||||||
|
@preconcurrency import VisionKit
|
||||||
|
|
||||||
class ImageGalleryContentViewController: UIViewController, GalleryContentViewController {
|
class ImageGalleryContentViewController: UIViewController, GalleryContentViewController {
|
||||||
let url: URL
|
let url: URL
|
||||||
|
@ -18,6 +19,12 @@ class ImageGalleryContentViewController: UIViewController, GalleryContentViewCon
|
||||||
let image: UIImage
|
let image: UIImage
|
||||||
let gifController: GIFController?
|
let gifController: GIFController?
|
||||||
|
|
||||||
|
@available(iOS 16.0, macCatalyst 17.0, *)
|
||||||
|
private static let analyzer = ImageAnalyzer()
|
||||||
|
private var _analysisInteraction: AnyObject?
|
||||||
|
@available(iOS 16.0, macCatalyst 17.0, *)
|
||||||
|
private var analysisInteraction: ImageAnalysisInteraction? { _analysisInteraction as? ImageAnalysisInteraction }
|
||||||
|
|
||||||
init(url: URL, caption: String?, originalData: Data?, image: UIImage, gifController: GIFController?) {
|
init(url: URL, caption: String?, originalData: Data?, image: UIImage, gifController: GIFController?) {
|
||||||
self.url = url
|
self.url = url
|
||||||
self.caption = caption
|
self.caption = caption
|
||||||
|
@ -40,6 +47,7 @@ class ImageGalleryContentViewController: UIViewController, GalleryContentViewCon
|
||||||
let imageView = GIFImageView(image: image)
|
let imageView = GIFImageView(image: image)
|
||||||
imageView.translatesAutoresizingMaskIntoConstraints = false
|
imageView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
imageView.contentMode = .scaleAspectFit
|
imageView.contentMode = .scaleAspectFit
|
||||||
|
imageView.isUserInteractionEnabled = true
|
||||||
view.addSubview(imageView)
|
view.addSubview(imageView)
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
imageView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
imageView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||||
|
@ -51,6 +59,22 @@ class ImageGalleryContentViewController: UIViewController, GalleryContentViewCon
|
||||||
if let gifController {
|
if let gifController {
|
||||||
gifController.attach(to: imageView)
|
gifController.attach(to: imageView)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if gifController == nil,
|
||||||
|
#available(iOS 16.0, macCatalyst 17.0, *) {
|
||||||
|
let interaction = ImageAnalysisInteraction(self)
|
||||||
|
self._analysisInteraction = interaction
|
||||||
|
interaction.preferredInteractionTypes = .automatic
|
||||||
|
imageView.addInteraction(interaction)
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
let result = try await ImageGalleryContentViewController.analyzer.analyze(image, configuration: ImageAnalyzer.Configuration([.text, .machineReadableCode]))
|
||||||
|
interaction.analysis = result
|
||||||
|
} catch {
|
||||||
|
// if analysis fails, we just don't show anything
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
@ -76,4 +100,18 @@ class ImageGalleryContentViewController: UIViewController, GalleryContentViewCon
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setControlsVisible(_ visible: Bool, animated: Bool) {
|
||||||
|
if #available(iOS 16.0, macCatalyst 17.0, *),
|
||||||
|
let analysisInteraction {
|
||||||
|
analysisInteraction.setSupplementaryInterfaceHidden(!visible, animated: animated)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(iOS 16.0, macCatalyst 17.0, *)
|
||||||
|
extension ImageGalleryContentViewController: ImageAnalysisInteractionDelegate {
|
||||||
|
func interaction(_ interaction: ImageAnalysisInteraction, shouldBeginAt point: CGPoint, for interactionType: ImageAnalysisInteraction.InteractionTypes) -> Bool {
|
||||||
|
return container?.galleryControlsVisible ?? true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ class LoadingGalleryContentViewController: UIViewController, GalleryContentViewC
|
||||||
if let wrapped = await provider() {
|
if let wrapped = await provider() {
|
||||||
self.wrapped = wrapped
|
self.wrapped = wrapped
|
||||||
wrapped.container = container
|
wrapped.container = container
|
||||||
|
wrapped.setControlsVisible(container?.galleryControlsVisible ?? false, animated: false)
|
||||||
|
|
||||||
addChild(wrapped)
|
addChild(wrapped)
|
||||||
wrapped.view.translatesAutoresizingMaskIntoConstraints = false
|
wrapped.view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
@ -99,4 +100,8 @@ class LoadingGalleryContentViewController: UIViewController, GalleryContentViewC
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setControlsVisible(_ visible: Bool, animated: Bool) {
|
||||||
|
wrapped?.setControlsVisible(visible, animated: animated)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue