diff --git a/Packages/Models/Sources/Models/MediaAttachement.swift b/Packages/Models/Sources/Models/MediaAttachement.swift index e4786b5b..e3a97213 100644 --- a/Packages/Models/Sources/Models/MediaAttachement.swift +++ b/Packages/Models/Sources/Models/MediaAttachement.swift @@ -1,7 +1,7 @@ import Foundation -public struct MediaAttachement: Codable, Identifiable { - public struct Meta: Codable { +public struct MediaAttachement: Codable, Identifiable, Hashable { + public struct Meta: Codable, Equatable { public let width: Int? public let height: Int? public let size: String? @@ -14,6 +14,10 @@ public struct MediaAttachement: Codable, Identifiable { case image, gifv } + public func hash(into hasher: inout Hasher) { + hasher.combine(id) + } + public let id: String public let type: String public var supportedType: SupportedType? { diff --git a/Packages/Status/Sources/Status/Row/StatusMediaPreviewView.swift b/Packages/Status/Sources/Status/Row/StatusMediaPreviewView.swift index 2d303a18..3790b227 100644 --- a/Packages/Status/Sources/Status/Row/StatusMediaPreviewView.swift +++ b/Packages/Status/Sources/Status/Row/StatusMediaPreviewView.swift @@ -31,23 +31,8 @@ public struct StatusMediaPreviewView: View { } } } - .sheet(item: $selectedMediaSheetManager.selectedAttachement) { attachement in - VStack { - Spacer() - AsyncImage( - url: attachement.url, - content: { image in - image - .resizable() - .aspectRatio(contentMode: .fit) - }, - placeholder: { - ProgressView() - .frame(maxWidth: 80, maxHeight: 80) - } - ) - Spacer() - } + .sheet(item: $selectedMediaSheetManager.selectedAttachement) { selectedAttachement in + makeSelectedAttachementsSheet(selectedAttachement: selectedAttachement) } } @@ -85,4 +70,32 @@ public struct StatusMediaPreviewView: View { } } } + + + private func makeSelectedAttachementsSheet(selectedAttachement: MediaAttachement) -> some View { + var attachements = attachements + attachements.removeAll(where: { $0.id == selectedAttachement.id }) + attachements.insert(selectedAttachement, at: 0) + return TabView { + ForEach(attachements) { attachement in + VStack { + Spacer() + AsyncImage( + url: attachement.url, + content: { image in + image + .resizable() + .aspectRatio(contentMode: .fit) + }, + placeholder: { + ProgressView() + .frame(maxWidth: 80, maxHeight: 80) + } + ) + Spacer() + } + } + } + .tabViewStyle(.page(indexDisplayMode: .always)) + } }