Skip to content

Commit

Permalink
Tweaks following code review
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Nov 15, 2024
1 parent e5ab176 commit acf821c
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 30 deletions.
10 changes: 5 additions & 5 deletions ElementX/Sources/Other/SwiftUI/Layout/TimelineMediaFrame.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ struct ImageRoomTimelineView: View {
mediaProvider: context.mediaProvider) {
placeholder
}
.timelineMediaFrame(height: timelineItem.content.imageInfo.size?.height,
aspectRatio: timelineItem.content.imageInfo.aspectRatio)
.timelineMediaFrame(imageInfo: timelineItem.content.imageInfo)
} else {
LoadableImage(mediaSource: timelineItem.content.thumbnailInfo?.source ?? timelineItem.content.imageInfo.source,
mediaType: .timelineItem,
Expand All @@ -57,8 +56,7 @@ struct ImageRoomTimelineView: View {
mediaProvider: context.mediaProvider) {
placeholder
}
.timelineMediaFrame(height: timelineItem.content.thumbnailInfo?.size?.height ?? timelineItem.content.imageInfo.size?.height,
aspectRatio: timelineItem.content.thumbnailInfo?.aspectRatio ?? timelineItem.content.imageInfo.aspectRatio)
.timelineMediaFrame(imageInfo: timelineItem.content.thumbnailInfo ?? timelineItem.content.imageInfo)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ struct StickerRoomTimelineView: View {

var body: some View {
TimelineStyler(timelineItem: timelineItem) {
LoadableImage(url: timelineItem.imageInfo.source.url,
LoadableImage(mediaSource: timelineItem.imageInfo.source,
mediaType: .timelineItem,
blurhash: timelineItem.blurhash,
size: timelineItem.imageInfo.size,
mediaProvider: context.mediaProvider) {
placeholder
}
.timelineMediaFrame(height: timelineItem.imageInfo.size?.height,
aspectRatio: timelineItem.imageInfo.aspectRatio)
.timelineMediaFrame(imageInfo: timelineItem.imageInfo)
.accessibilityElement(children: .ignore)
.accessibilityLabel("\(L10n.commonSticker), \(timelineItem.body)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ struct VideoRoomTimelineView: View {
TimelineStyler(timelineItem: timelineItem) {
VStack(alignment: .leading, spacing: 4) {
thumbnail
.timelineMediaFrame(height: timelineItem.content.thumbnailInfo?.size?.height,
aspectRatio: timelineItem.content.thumbnailInfo?.aspectRatio)
.timelineMediaFrame(imageInfo: timelineItem.content.thumbnailInfo)
.accessibilityElement(children: .ignore)
.accessibilityLabel(L10n.commonVideo)
// This clip shape is distinct from the one in the styler as that one
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit acf821c

Please sign in to comment.