From bd0709c0ba9bb6a2013c06c363d4dd8c57a59ea5 Mon Sep 17 00:00:00 2001 From: Mustapha-Tarek Ben Lechhab Date: Thu, 13 Feb 2025 15:23:07 +0100 Subject: [PATCH] PLAYNEXT-1271 Fix layout of media cell depending on media type --- Application/Sources/UI/Views/MediaCell.swift | 29 +++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Application/Sources/UI/Views/MediaCell.swift b/Application/Sources/UI/Views/MediaCell.swift index 57b8c1c62..648a2804f 100644 --- a/Application/Sources/UI/Views/MediaCell.swift +++ b/Application/Sources/UI/Views/MediaCell.swift @@ -63,6 +63,32 @@ struct MediaCell: View, PrimaryColorSettable, SecondaryColorSettable { isSelected && media != nil } + private var mediaVisualViewFrame: CGSize { + if ApplicationConfiguration.shared.arePodcastImagesEnabled, media?.mediaType == .audio, layout == .adaptive { + .init(width: SmallMediaSquareCellSize.height() * SmallMediaSquareCellSize.defaultAspectRatio, height: SmallMediaSquareCellSize.height()) + } else if ApplicationConfiguration.shared.arePodcastImagesEnabled, media?.mediaType == .audio { + .init(width: MediaSquareCellSize.height() * MediaSquareCellSize.defaultAspectRatio, height: MediaSquareCellSize.height()) + } else { + .init(width: MediaCellSize.height(horizontalSizeClass: horizontalSizeClass) * MediaCellSize.defaultAspectRatio, height: MediaCellSize.height(horizontalSizeClass: horizontalSizeClass)) + } + } + + private var aspectRatio: CGFloat { + if ApplicationConfiguration.shared.arePodcastImagesEnabled, media?.mediaType == .audio { + MediaSquareCellSize.defaultAspectRatio + } else { + MediaCellSize.defaultAspectRatio + } + } + + private var contentMode: ContentMode { + if ApplicationConfiguration.shared.arePodcastImagesEnabled, media?.mediaType == .audio { + .fill + } else { + .fit + } + } + init(media: SRGMedia?, style: Style, layout: Layout = .adaptive, action: (() -> Void)? = nil) { self.media = media self.style = style @@ -88,10 +114,11 @@ struct MediaCell: View, PrimaryColorSettable, SecondaryColorSettable { Stack(direction: .vertical, spacing: 0) { Stack(direction: direction, spacing: 0) { MediaVisualView(media: media, size: .small, embeddedDirection: direction) + .aspectRatio(aspectRatio, contentMode: contentMode) .selectionAppearance(when: hasSelectionAppearance, while: isEditing) .cornerRadius(LayoutStandardViewCornerRadius) .redactable() - .layoutPriority(1) + .frame(size: mediaVisualViewFrame) DescriptionView(media: media, style: style, embeddedDirection: direction) .primaryColor(primaryColor) .secondaryColor(secondaryColor)