Group image and video metadata in specialised structs (#3518)

This commit is contained in:
Stefan Ceriu
2024-11-15 15:00:27 +02:00
committed by GitHub
parent 4ea276dc99
commit ef288a9662
27 changed files with 232 additions and 214 deletions
@@ -10,18 +10,18 @@ import SwiftUI
extension View {
/// Constrains the max height of a media item in the timeline, whilst preserving its aspect ratio.
@ViewBuilder
func timelineMediaFrame(height contentHeight: CGFloat?, aspectRatio contentAspectRatio: CGFloat?) -> some View {
func timelineMediaFrame(imageInfo: ImageInfoProxy?) -> some View {
let defaultMediaSize = 100.0
let minMediaHeight = 100.0
let maxMediaHeight = 300.0
if let contentHeight, contentHeight < minMediaHeight { // Special case very small images
aspectRatio(contentAspectRatio, contentMode: .fit)
if let contentHeight = imageInfo?.size?.height, contentHeight < minMediaHeight { // Special case very small images
aspectRatio(imageInfo?.aspectRatio, contentMode: .fit)
.frame(minHeight: minMediaHeight, maxHeight: minMediaHeight)
} else {
if let contentAspectRatio {
if let contentAspectRatio = imageInfo?.aspectRatio {
aspectRatio(contentAspectRatio, contentMode: .fit)
.frame(maxHeight: min(maxMediaHeight, max(minMediaHeight, contentHeight ?? .infinity)))
.frame(maxHeight: min(maxMediaHeight, max(minMediaHeight, imageInfo?.size?.height ?? .infinity)))
// Required to prevent the reply details to get higher priority in rendering the width of the view.
.aspectRatio(contentAspectRatio, contentMode: .fit)
} else { // Otherwise force the image to be `defaultMediaSize` x `defaultMediaSize`