Focus on selected media in viewer

This commit is contained in:
Thomas Ricouard 2022-12-19 19:04:07 +01:00
parent 00b5e07acd
commit d995b7c996
2 changed files with 36 additions and 19 deletions

View file

@ -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? {

View file

@ -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))
}
}