From 0ea6245d01f61a90cf689766547e111eb10bf595 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 18 Sep 2023 13:12:35 +0300 Subject: [PATCH] Threaded layout fixes (#1730) * Fixes #1727 - Layout issues caused by the new timelineMediaFrame * Better handle small media thumbnails * fixed an issue where sometimes the reply gets greedier than the content --------- Co-authored-by: Mauro Romito --- .../Other/SwiftUI/Layout/TimelineMediaFrame.swift | 15 +++++++++++++-- .../View/Timeline/ImageRoomTimelineView.swift | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ElementX/Sources/Other/SwiftUI/Layout/TimelineMediaFrame.swift b/ElementX/Sources/Other/SwiftUI/Layout/TimelineMediaFrame.swift index 80825a461..db6d1de23 100644 --- a/ElementX/Sources/Other/SwiftUI/Layout/TimelineMediaFrame.swift +++ b/ElementX/Sources/Other/SwiftUI/Layout/TimelineMediaFrame.swift @@ -18,8 +18,19 @@ 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 { - aspectRatio(contentAspectRatio, contentMode: .fit) - .frame(maxHeight: min(300, max(100, contentHeight ?? .infinity))) + let minMediaHeight = 100.0 + let maxMediaHeight = 300.0 + + if let contentHeight, contentHeight < minMediaHeight { // Special case very small images + aspectRatio(contentAspectRatio, contentMode: .fit) + .frame(minHeight: minMediaHeight, maxHeight: minMediaHeight) + } else { + aspectRatio(contentAspectRatio, contentMode: .fit) + .frame(maxHeight: min(maxMediaHeight, max(minMediaHeight, contentHeight ?? .infinity))) + // Required to prevent the reply details to get higher priority in rendering the width of the view. + .aspectRatio(contentAspectRatio, contentMode: .fit) + } } } diff --git a/ElementX/Sources/Screens/RoomScreen/View/Timeline/ImageRoomTimelineView.swift b/ElementX/Sources/Screens/RoomScreen/View/Timeline/ImageRoomTimelineView.swift index df7dbd7b4..d1f089cbf 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Timeline/ImageRoomTimelineView.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Timeline/ImageRoomTimelineView.swift @@ -29,7 +29,7 @@ struct ImageRoomTimelineView: View { placeholder } .timelineMediaFrame(height: timelineItem.content.height, - aspectRatio: timelineItem.content.height) + aspectRatio: timelineItem.content.aspectRatio) .accessibilityElement(children: .ignore) .accessibilityLabel(L10n.commonImage) }