2021-04-28 09:02:34 +02:00
|
|
|
//
|
|
|
|
// MediaPreviewTransitionItem.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-4-28.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2021-04-28 13:06:45 +02:00
|
|
|
import CoreData
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonUI
|
2021-04-28 09:02:34 +02:00
|
|
|
|
|
|
|
class MediaPreviewTransitionItem: Identifiable {
|
|
|
|
|
|
|
|
let id: UUID
|
2021-04-28 13:06:45 +02:00
|
|
|
let source: Source
|
|
|
|
var previewableViewController: MediaPreviewableViewController
|
2021-04-28 09:02:34 +02:00
|
|
|
|
2021-04-28 13:06:45 +02:00
|
|
|
// source
|
|
|
|
var image: UIImage?
|
|
|
|
var aspectRatio: CGSize?
|
|
|
|
var initialFrame: CGRect? = nil
|
|
|
|
var sourceImageView: UIImageView?
|
2021-04-28 14:10:17 +02:00
|
|
|
var sourceImageViewCornerRadius: CGFloat?
|
2022-02-09 13:35:19 +01:00
|
|
|
|
2021-04-28 13:06:45 +02:00
|
|
|
// target
|
|
|
|
var targetFrame: CGRect? = nil
|
|
|
|
|
|
|
|
// transitioning
|
2022-02-09 13:35:19 +01:00
|
|
|
var transitionView: UIView?
|
2021-04-28 09:02:34 +02:00
|
|
|
var snapshotRaw: UIView?
|
|
|
|
var snapshotTransitioning: UIView?
|
|
|
|
var touchOffset: CGVector = CGVector.zero
|
2021-05-11 10:11:00 +02:00
|
|
|
var interactiveTransitionMaskView: UIView?
|
|
|
|
var interactiveTransitionMaskLayer: CAShapeLayer?
|
2021-04-28 09:02:34 +02:00
|
|
|
|
2022-02-09 13:35:19 +01:00
|
|
|
init(
|
|
|
|
id: UUID = UUID(),
|
|
|
|
source: Source,
|
|
|
|
previewableViewController: MediaPreviewableViewController
|
|
|
|
) {
|
2021-04-28 09:02:34 +02:00
|
|
|
self.id = id
|
2021-04-28 13:06:45 +02:00
|
|
|
self.source = source
|
|
|
|
self.previewableViewController = previewableViewController
|
2021-04-28 09:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-04-28 13:06:45 +02:00
|
|
|
|
|
|
|
extension MediaPreviewTransitionItem {
|
|
|
|
enum Source {
|
2022-01-27 14:23:39 +01:00
|
|
|
case attachment(MediaView)
|
|
|
|
case attachments(MediaGridContainerView)
|
2021-04-28 14:10:17 +02:00
|
|
|
case profileAvatar(ProfileHeaderView)
|
2021-04-28 14:36:10 +02:00
|
|
|
case profileBanner(ProfileHeaderView)
|
2021-04-28 14:10:17 +02:00
|
|
|
|
|
|
|
func updateAppearance(position: UIViewAnimatingPosition, index: Int?) {
|
|
|
|
let alpha: CGFloat = position == .end ? 1 : 0
|
|
|
|
switch self {
|
2022-01-27 14:23:39 +01:00
|
|
|
case .attachment(let mediaView):
|
|
|
|
mediaView.alpha = alpha
|
|
|
|
case .attachments(let mediaGridContainerView):
|
2021-04-28 14:10:17 +02:00
|
|
|
if let index = index {
|
2022-02-09 13:35:19 +01:00
|
|
|
mediaGridContainerView.setAlpha(alpha, index: index)
|
2021-04-28 14:10:17 +02:00
|
|
|
} else {
|
2022-01-27 14:23:39 +01:00
|
|
|
mediaGridContainerView.setAlpha(alpha)
|
2021-04-28 14:10:17 +02:00
|
|
|
}
|
|
|
|
case .profileAvatar(let profileHeaderView):
|
2022-01-27 14:23:39 +01:00
|
|
|
profileHeaderView.avatarButton.alpha = alpha
|
2021-04-28 14:36:10 +02:00
|
|
|
case .profileBanner:
|
|
|
|
break // keep source
|
2021-04-28 14:10:17 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-28 13:06:45 +02:00
|
|
|
}
|
|
|
|
}
|