WIP: show attachment full screen

pull/874/head
ryanzhao 2 years ago
parent bf3b870c8f
commit f988f272d1

@ -566,13 +566,14 @@ public class MediaGalleryViewModel {
return navController return navController
} }
@ViewBuilder
public static func createDetailViewSwiftUI( public static func createDetailViewSwiftUI(
for threadId: String, for threadId: String,
threadVariant: SessionThread.Variant, threadVariant: SessionThread.Variant,
interactionId: Int64, interactionId: Int64,
selectedAttachmentId: String, selectedAttachmentId: String,
options: [MediaGalleryOption] options: [MediaGalleryOption]
) -> (any UIViewControllerRepresentable)? { ) -> some View {
// Load the data for the album immediately (needed before pushing to the screen so // Load the data for the album immediately (needed before pushing to the screen so
// transitions work nicely) // transitions work nicely)
let viewModel: MediaGalleryViewModel = MediaGalleryViewModel( let viewModel: MediaGalleryViewModel = MediaGalleryViewModel(
@ -581,16 +582,15 @@ public class MediaGalleryViewModel {
isPagedData: false, isPagedData: false,
mediaType: .media mediaType: .media
) )
viewModel.loadAndCacheAlbumData(for: interactionId, in: threadId) let _ = viewModel.loadAndCacheAlbumData(for: interactionId, in: threadId)
viewModel.replaceAlbumObservation(toObservationFor: interactionId) let _ = viewModel.replaceAlbumObservation(toObservationFor: interactionId)
guard if
!viewModel.albumData.isEmpty, !viewModel.albumData.isEmpty,
let initialItem: Item = viewModel.albumData[interactionId]?.first(where: { item -> Bool in let initialItem: Item = viewModel.albumData[interactionId]?.first(where: { item -> Bool in
item.attachment.id == selectedAttachmentId item.attachment.id == selectedAttachmentId
}) })
else { return nil } {
let pageViewController: MediaPageViewController = MediaPageViewController( let pageViewController: MediaPageViewController = MediaPageViewController(
viewModel: viewModel, viewModel: viewModel,
initialItem: initialItem, initialItem: initialItem,
@ -600,8 +600,11 @@ public class MediaGalleryViewModel {
viewControllers: [pageViewController], viewControllers: [pageViewController],
transitioningDelegate: pageViewController transitioningDelegate: pageViewController
) )
navController
return navController }
else {
EmptyView()
}
} }
public static func createMediaTileViewController( public static func createMediaTileViewController(

@ -6,6 +6,7 @@ import SessionSnodeKit
struct MessageInfoView: View { struct MessageInfoView: View {
@State var index = 1 @State var index = 1
@State var showingAttachmentFullScreen = false
var actions: [ContextMenuVC.Action] var actions: [ContextMenuVC.Action]
var messageViewModel: MessageViewModel var messageViewModel: MessageViewModel
var isMessageFailed: Bool { var isMessageFailed: Bool {
@ -98,6 +99,8 @@ struct MessageInfoView: View {
} }
if let attachments = messageViewModel.attachments { if let attachments = messageViewModel.attachments {
let attachment: Attachment = attachments[(index - 1 + attachments.count) % attachments.count]
ZStack(alignment: .bottomTrailing) { ZStack(alignment: .bottomTrailing) {
if attachments.count > 1 { if attachments.count > 1 {
// Attachment carousel view // Attachment carousel view
@ -135,7 +138,7 @@ struct MessageInfoView: View {
} }
Button { Button {
// TODO: full screen function self.showingAttachmentFullScreen.toggle()
} label: { } label: {
ZStack { ZStack {
Circle() Circle()
@ -146,6 +149,15 @@ struct MessageInfoView: View {
} }
.frame(width: 26, height: 26) .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( .padding(
EdgeInsets( EdgeInsets(
top: 0, top: 0,
@ -165,7 +177,6 @@ struct MessageInfoView: View {
) )
// Attachment Info // Attachment Info
let attachment: Attachment = attachments[(index - 1 + attachments.count) % attachments.count]
ZStack { ZStack {
RoundedRectangle(cornerRadius: 17) RoundedRectangle(cornerRadius: 17)
.fill(themeColor: .backgroundSecondary) .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 { struct InfoBlock<Content>: View where Content: View {

Loading…
Cancel
Save