mastodon-ios/Mastodon/Scene/Transition/MediaPreview/MediaPreviewTransitionItem....

74 lines
2.0 KiB
Swift
Raw Normal View History

//
// MediaPreviewTransitionItem.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-4-28.
//
import UIKit
import CoreData
import MastodonUI
class MediaPreviewTransitionItem: Identifiable {
let id: UUID
let source: Source
var previewableViewController: MediaPreviewableViewController
// 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?
// target
var targetFrame: CGRect? = nil
// transitioning
var transitionView: UIView?
var snapshotRaw: UIView?
var snapshotTransitioning: UIView?
var touchOffset: CGVector = CGVector.zero
var interactiveTransitionMaskView: UIView?
var interactiveTransitionMaskLayer: CAShapeLayer?
init(
id: UUID = UUID(),
source: Source,
previewableViewController: MediaPreviewableViewController
) {
self.id = id
self.source = source
self.previewableViewController = previewableViewController
}
}
extension MediaPreviewTransitionItem {
enum Source {
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 {
case .attachment(let mediaView):
mediaView.alpha = alpha
case .attachments(let mediaGridContainerView):
2021-04-28 14:10:17 +02:00
if let index = index {
mediaGridContainerView.setAlpha(alpha, index: index)
2021-04-28 14:10:17 +02:00
} else {
mediaGridContainerView.setAlpha(alpha)
2021-04-28 14:10:17 +02:00
}
case .profileAvatar(let profileHeaderView):
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
}
}
}
}