Better Media viewer

This commit is contained in:
Thomas Ricouard 2022-12-20 08:14:57 +01:00
parent d995b7c996
commit 9d7f93303f
2 changed files with 36 additions and 26 deletions

View File

@ -14,6 +14,8 @@ struct StatusCardView: View {
content: { image in content: { image in
image.resizable() image.resizable()
.aspectRatio(contentMode: .fill) .aspectRatio(contentMode: .fill)
.frame(maxHeight: 200)
.clipped()
}, },
placeholder: { placeholder: {
ProgressView() ProgressView()

View File

@ -39,10 +39,10 @@ public struct StatusMediaPreviewView: View {
@ViewBuilder @ViewBuilder
private func makePreview(attachement: MediaAttachement) -> some View { private func makePreview(attachement: MediaAttachement) -> some View {
if let type = attachement.supportedType { if let type = attachement.supportedType {
switch type { Group {
case .image: GeometryReader { proxy in
Group { switch type {
GeometryReader { proxy in case .image:
AsyncImage( AsyncImage(
url: attachement.url, url: attachement.url,
content: { image in content: { image in
@ -57,16 +57,17 @@ public struct StatusMediaPreviewView: View {
.frame(maxWidth: 80, maxHeight: 80) .frame(maxWidth: 80, maxHeight: 80)
} }
) )
case .gifv:
VideoPlayer(player: AVPlayer(url: attachement.url))
.frame(width: proxy.frame(in: .local).width)
.frame(height: attachements.count > 2 ? 100 : 200)
} }
.frame(height: attachements.count > 2 ? 100 : 200)
} }
.cornerRadius(4) .frame(height: attachements.count > 2 ? 100 : 200)
.onTapGesture { }
selectedMediaSheetManager.selectedAttachement = attachement .cornerRadius(4)
} .onTapGesture {
case .gifv: selectedMediaSheetManager.selectedAttachement = attachement
VideoPlayer(player: AVPlayer(url: attachement.url))
.frame(maxHeight: attachements.count > 2 ? 100 : 200)
} }
} }
} }
@ -78,21 +79,28 @@ public struct StatusMediaPreviewView: View {
attachements.insert(selectedAttachement, at: 0) attachements.insert(selectedAttachement, at: 0)
return TabView { return TabView {
ForEach(attachements) { attachement in ForEach(attachements) { attachement in
VStack { if let type = attachement.supportedType {
Spacer() VStack {
AsyncImage( Spacer()
url: attachement.url, switch type {
content: { image in case .image:
image AsyncImage(
.resizable() url: attachement.url,
.aspectRatio(contentMode: .fit) content: { image in
}, image
placeholder: { .resizable()
ProgressView() .aspectRatio(contentMode: .fit)
.frame(maxWidth: 80, maxHeight: 80) },
placeholder: {
ProgressView()
.frame(maxWidth: 80, maxHeight: 80)
}
)
case .gifv:
VideoPlayer(player: AVPlayer(url: attachement.url))
} }
) Spacer()
Spacer() }
} }
} }
} }