mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
WIP: media preview view
This commit is contained in:
parent
8a2264e95f
commit
da0fb2602c
|
@ -1558,7 +1558,10 @@ extension ConversationVC:
|
|||
// MARK: - ContextMenuActionDelegate
|
||||
|
||||
func info(_ cellViewModel: MessageViewModel) {
|
||||
let mediaInfoVC = MediaInfoVC(attachments: (cellViewModel.attachments ?? []))
|
||||
let mediaInfoVC = MediaInfoVC(
|
||||
attachments: (cellViewModel.attachments ?? []),
|
||||
isOutgoing: (cellViewModel.variant == .standardOutgoing)
|
||||
)
|
||||
navigationController?.pushViewController(mediaInfoVC, animated: true)
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,7 @@ public class MediaAlbumView: UIStackView {
|
|||
MediaView(
|
||||
mediaCache: mediaCache,
|
||||
attachment: $0,
|
||||
isOutgoing: isOutgoing,
|
||||
maxMessageWidth: maxMessageWidth
|
||||
isOutgoing: isOutgoing
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ public class MediaView: UIView {
|
|||
private let mediaCache: NSCache<NSString, AnyObject>
|
||||
public let attachment: Attachment
|
||||
private let isOutgoing: Bool
|
||||
private let maxMessageWidth: CGFloat
|
||||
private var loadBlock: (() -> Void)?
|
||||
private var unloadBlock: (() -> Void)?
|
||||
|
||||
|
@ -48,13 +47,11 @@ public class MediaView: UIView {
|
|||
public required init(
|
||||
mediaCache: NSCache<NSString, AnyObject>,
|
||||
attachment: Attachment,
|
||||
isOutgoing: Bool,
|
||||
maxMessageWidth: CGFloat
|
||||
isOutgoing: Bool
|
||||
) {
|
||||
self.mediaCache = mediaCache
|
||||
self.attachment = attachment
|
||||
self.isOutgoing = isOutgoing
|
||||
self.maxMessageWidth = maxMessageWidth
|
||||
|
||||
super.init(frame: .zero)
|
||||
|
||||
|
|
|
@ -8,20 +8,48 @@ extension MediaInfoVC {
|
|||
final class MediaPreviewView: UIView {
|
||||
private static let cornerRadius: CGFloat = 8
|
||||
|
||||
private let mediaCache: NSCache<NSString, AnyObject>
|
||||
private let attachment: Attachment
|
||||
private let isOutgoing: Bool
|
||||
|
||||
// MARK: - UI
|
||||
|
||||
private lazy var mediaView: MediaView = {
|
||||
let result: MediaView = MediaView.init(
|
||||
mediaCache: mediaCache,
|
||||
attachment: attachment,
|
||||
isOutgoing: isOutgoing
|
||||
)
|
||||
|
||||
return result
|
||||
}()
|
||||
|
||||
private lazy var fullScreenButton: UIButton = {
|
||||
let result: UIButton = UIButton(type: .custom)
|
||||
result.setImage(
|
||||
UIImage(systemName: "arrow.up.left.and.arrow.down.right")?
|
||||
.withRenderingMode(.alwaysTemplate),
|
||||
for: .normal
|
||||
)
|
||||
result.themeTintColor = .textPrimary
|
||||
result.backgroundColor = .init(white: 0, alpha: 0.4)
|
||||
result.layer.cornerRadius = 14
|
||||
result.set(.width, to: 28)
|
||||
result.set(.height, to: 28)
|
||||
|
||||
return result
|
||||
}()
|
||||
|
||||
// MARK: - Lifecycle
|
||||
|
||||
init(attachment: Attachment) {
|
||||
init(
|
||||
mediaCache: NSCache<NSString, AnyObject>,
|
||||
attachment: Attachment,
|
||||
isOutgoing: Bool
|
||||
) {
|
||||
self.mediaCache = mediaCache
|
||||
self.attachment = attachment
|
||||
self.isOutgoing = isOutgoing
|
||||
|
||||
super.init(frame: CGRect.zero)
|
||||
self.accessibilityLabel = "Media info"
|
||||
|
@ -37,7 +65,17 @@ extension MediaInfoVC {
|
|||
}
|
||||
|
||||
private func setUpViewHierarchy() {
|
||||
set(.width, to: 293)
|
||||
set(.height, to: 293)
|
||||
|
||||
addSubview(mediaView)
|
||||
mediaView.pin(to: self)
|
||||
|
||||
addSubview(fullScreenButton)
|
||||
fullScreenButton.pin(.trailing, to: .trailing, of: self, withInset: -Values.smallSpacing)
|
||||
fullScreenButton.pin(.bottom, to: .bottom, of: self, withInset: -Values.smallSpacing)
|
||||
|
||||
mediaView.loadMedia()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,10 +7,19 @@ import SessionUtilitiesKit
|
|||
final class MediaInfoVC: BaseVC {
|
||||
|
||||
private let attachments: [Attachment]
|
||||
private let isOutgoing: Bool
|
||||
|
||||
// FIXME: Would be good to create a Swift-based cache and replace this
|
||||
lazy var mediaCache: NSCache<NSString, AnyObject> = {
|
||||
let result = NSCache<NSString, AnyObject>()
|
||||
result.countLimit = 40
|
||||
return result
|
||||
}()
|
||||
|
||||
// MARK: - Initialization
|
||||
|
||||
init(attachments: [Attachment]) {
|
||||
init(attachments: [Attachment], isOutgoing: Bool) {
|
||||
self.isOutgoing = isOutgoing
|
||||
self.attachments = attachments
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
@ -31,9 +40,18 @@ final class MediaInfoVC: BaseVC {
|
|||
self.title = "Message Info"
|
||||
|
||||
attachments.forEach {
|
||||
let mediaPreviewView: MediaPreviewView = MediaPreviewView(
|
||||
mediaCache: mediaCache,
|
||||
attachment: $0,
|
||||
isOutgoing: isOutgoing)
|
||||
let mediaInfoView: MediaInfoView = MediaInfoView(attachment: $0)
|
||||
self.view.addSubview(mediaInfoView)
|
||||
mediaInfoView.center(in: self.view)
|
||||
|
||||
let stackView: UIStackView = UIStackView(arrangedSubviews: [ mediaPreviewView, mediaInfoView ])
|
||||
stackView.axis = .vertical
|
||||
stackView.spacing = Values.largeSpacing
|
||||
|
||||
self.view.addSubview(stackView)
|
||||
stackView.center(in: self.view)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue