From f988f272d142ca735c75ae77cf61da98460c112a Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 1 Aug 2023 17:01:20 +1000 Subject: [PATCH] WIP: show attachment full screen --- .../MediaGalleryViewModel.swift | 37 ++++++++++--------- .../MessageInfoView.swift | 28 +++++++------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Session/Media Viewing & Editing/MediaGalleryViewModel.swift b/Session/Media Viewing & Editing/MediaGalleryViewModel.swift index f63ed5264..e54b2a21d 100644 --- a/Session/Media Viewing & Editing/MediaGalleryViewModel.swift +++ b/Session/Media Viewing & Editing/MediaGalleryViewModel.swift @@ -566,13 +566,14 @@ public class MediaGalleryViewModel { return navController } + @ViewBuilder public static func createDetailViewSwiftUI( for threadId: String, threadVariant: SessionThread.Variant, interactionId: Int64, selectedAttachmentId: String, options: [MediaGalleryOption] - ) -> (any UIViewControllerRepresentable)? { + ) -> some View { // Load the data for the album immediately (needed before pushing to the screen so // transitions work nicely) let viewModel: MediaGalleryViewModel = MediaGalleryViewModel( @@ -581,27 +582,29 @@ public class MediaGalleryViewModel { isPagedData: false, mediaType: .media ) - viewModel.loadAndCacheAlbumData(for: interactionId, in: threadId) - viewModel.replaceAlbumObservation(toObservationFor: interactionId) + let _ = viewModel.loadAndCacheAlbumData(for: interactionId, in: threadId) + let _ = viewModel.replaceAlbumObservation(toObservationFor: interactionId) - guard + if !viewModel.albumData.isEmpty, let initialItem: Item = viewModel.albumData[interactionId]?.first(where: { item -> Bool in item.attachment.id == selectedAttachmentId }) - else { return nil } - - let pageViewController: MediaPageViewController = MediaPageViewController( - viewModel: viewModel, - initialItem: initialItem, - options: options - ) - let navController = MediaGalleryNavigationController_SwiftUI( - viewControllers: [pageViewController], - transitioningDelegate: pageViewController - ) - - return navController + { + let pageViewController: MediaPageViewController = MediaPageViewController( + viewModel: viewModel, + initialItem: initialItem, + options: options + ) + let navController = MediaGalleryNavigationController_SwiftUI( + viewControllers: [pageViewController], + transitioningDelegate: pageViewController + ) + navController + } + else { + EmptyView() + } } public static func createMediaTileViewController( diff --git a/Session/Media Viewing & Editing/MessageInfoView.swift b/Session/Media Viewing & Editing/MessageInfoView.swift index 899db5321..1abc131e9 100644 --- a/Session/Media Viewing & Editing/MessageInfoView.swift +++ b/Session/Media Viewing & Editing/MessageInfoView.swift @@ -6,6 +6,7 @@ import SessionSnodeKit struct MessageInfoView: View { @State var index = 1 + @State var showingAttachmentFullScreen = false var actions: [ContextMenuVC.Action] var messageViewModel: MessageViewModel var isMessageFailed: Bool { @@ -98,6 +99,8 @@ struct MessageInfoView: View { } if let attachments = messageViewModel.attachments { + let attachment: Attachment = attachments[(index - 1 + attachments.count) % attachments.count] + ZStack(alignment: .bottomTrailing) { if attachments.count > 1 { // Attachment carousel view @@ -135,7 +138,7 @@ struct MessageInfoView: View { } Button { - // TODO: full screen function + self.showingAttachmentFullScreen.toggle() } label: { ZStack { Circle() @@ -146,6 +149,15 @@ struct MessageInfoView: View { } .frame(width: 26, height: 26) } + .sheet(isPresented: $showingAttachmentFullScreen) { + MediaGalleryViewModel.createDetailViewSwiftUI( + for: messageViewModel.threadId, + threadVariant: messageViewModel.threadVariant, + interactionId: messageViewModel.id, + selectedAttachmentId: attachment.id, + options: [ .sliderEnabled ] + ) + } .padding( EdgeInsets( top: 0, @@ -165,7 +177,6 @@ struct MessageInfoView: View { ) // Attachment Info - let attachment: Attachment = attachments[(index - 1 + attachments.count) % attachments.count] ZStack { RoundedRectangle(cornerRadius: 17) .fill(themeColor: .backgroundSecondary) @@ -406,19 +417,6 @@ struct MessageInfoView: View { } } } - - private func showMediaFullScreen(attachment: Attachment) { - let viewController: UIViewController? = MediaGalleryViewModel.createDetailViewController( - for: messageViewModel.threadId, - threadVariant: messageViewModel.threadVariant, - interactionId: messageViewModel.id, - selectedAttachmentId: attachment.id, - options: [ .sliderEnabled ] - ) - if let viewController: UIViewController = viewController { - viewController.transitioningDelegate = nil - } - } } struct InfoBlock: View where Content: View {