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 <mauro.romito@element.io>
This commit is contained in:
Stefan Ceriu
2023-09-18 13:12:35 +03:00
committed by GitHub
parent fd6711bbc7
commit aff3b781ad
2 changed files with 14 additions and 3 deletions
@@ -18,8 +18,19 @@ import SwiftUI
extension View { extension View {
/// Constrains the max height of a media item in the timeline, whilst preserving its aspect ratio. /// 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(height contentHeight: CGFloat?, aspectRatio contentAspectRatio: CGFloat?) -> some View {
aspectRatio(contentAspectRatio, contentMode: .fit) let minMediaHeight = 100.0
.frame(maxHeight: min(300, max(100, contentHeight ?? .infinity))) 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)
}
} }
} }
@@ -29,7 +29,7 @@ struct ImageRoomTimelineView: View {
placeholder placeholder
} }
.timelineMediaFrame(height: timelineItem.content.height, .timelineMediaFrame(height: timelineItem.content.height,
aspectRatio: timelineItem.content.height) aspectRatio: timelineItem.content.aspectRatio)
.accessibilityElement(children: .ignore) .accessibilityElement(children: .ignore)
.accessibilityLabel(L10n.commonImage) .accessibilityLabel(L10n.commonImage)
} }