diff --git a/Packages/DesignSystem/Sources/DesignSystem/SceneDelegate.swift b/Packages/DesignSystem/Sources/DesignSystem/SceneDelegate.swift index 44881c96..c93ba21d 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/SceneDelegate.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/SceneDelegate.swift @@ -8,6 +8,10 @@ import UIKit window?.bounds.size.width ?? UIScreen.main.bounds.size.width } + public var windowHeight: CGFloat { + window?.bounds.size.height ?? UIScreen.main.bounds.size.height + } + public func scene(_ scene: UIScene, willConnectTo _: UISceneSession, options _: UIScene.ConnectionOptions) diff --git a/Packages/Status/Sources/Status/Row/Subviews/StatusRowMediaPreviewView.swift b/Packages/Status/Sources/Status/Row/Subviews/StatusRowMediaPreviewView.swift index 6131a164..13e9441b 100644 --- a/Packages/Status/Sources/Status/Row/Subviews/StatusRowMediaPreviewView.swift +++ b/Packages/Status/Sources/Status/Row/Subviews/StatusRowMediaPreviewView.swift @@ -68,7 +68,8 @@ public struct StatusRowMediaPreviewView: View { imageMaxHeight: imageMaxHeight, sensitive: sensitive, appLayoutWidth: appLayoutWidth, - availableWidth: availableWidth + availableWidth: availableWidth, + availableHeight: sceneDelegate.windowHeight ) .accessibilityElement(children: .ignore) .accessibilityLabel(Self.accessibilityLabel(for: attachments[0])) @@ -200,6 +201,7 @@ private struct FeaturedImagePreView: View { let sensitive: Bool let appLayoutWidth: CGFloat let availableWidth: CGFloat + let availableHeight: CGFloat @Environment(\.isSecondaryColumn) private var isSecondaryColumn: Bool @Environment(Theme.self) private var theme @@ -207,7 +209,7 @@ private struct FeaturedImagePreView: View { var body: some View { let size: CGSize = size(for: attachment) ?? .init(width: imageMaxHeight, height: imageMaxHeight) - let newSize = imageSize(from: size, newWidth: availableWidth - appLayoutWidth) + let newSize = imageSize(from: size) Group { switch attachment.supportedType { case .image: @@ -255,13 +257,27 @@ private struct FeaturedImagePreView: View { return .init(width: CGFloat(width), height: CGFloat(height)) } - private func imageSize(from: CGSize, newWidth: CGFloat) -> CGSize { + private func imageSize(from: CGSize) -> CGSize { if isCompact || theme.statusDisplayStyle == .compact || isSecondaryColumn { return .init(width: imageMaxHeight, height: imageMaxHeight) } - let ratio = newWidth / from.width - let newHeight = from.height * ratio - return .init(width: newWidth, height: newHeight) + + let boxWidth = availableWidth - appLayoutWidth + let boxHeight = availableHeight * 0.8 // use only 80% of window height to leave room for text + + if from.width <= boxWidth && from.height <= boxHeight { + // intrinsic size of image fits just fine + return from + } + + // shrink image proportionally to fit inside the box + let xRatio = boxWidth / from.width + let yRatio = boxHeight / from.height + if xRatio < yRatio { + return .init(width: boxWidth, height: from.height * xRatio) + } else { + return .init(width: from.width * yRatio, height: boxHeight) + } } }