WIP: show attachment full screen

This commit is contained in:
ryanzhao 2023-08-01 17:01:20 +10:00
parent bf3b870c8f
commit f988f272d1
2 changed files with 33 additions and 32 deletions

View File

@ -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(

View File

@ -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<Content>: View where Content: View {