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 6425dc3f32
commit 0ea6245d01
2 changed files with 14 additions and 3 deletions

View File

@@ -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)
}
}
}

View File

@@ -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)
}