diff --git a/Tusker/Extensions/StatusStateResolver.swift b/Tusker/Extensions/StatusStateResolver.swift index 266c2afa..4c5901bd 100644 --- a/Tusker/Extensions/StatusStateResolver.swift +++ b/Tusker/Extensions/StatusStateResolver.swift @@ -14,7 +14,7 @@ extension CollapseState { func resolveFor(status: StatusMO, height: CGFloat, textLength: Int? = nil) { let longEnoughToCollapse: Bool if Preferences.shared.collapseLongPosts, - height > 500 || (textLength != nil && textLength! > 500) { + height > 600 || (textLength != nil && textLength! > 500) { longEnoughToCollapse = true } else { longEnoughToCollapse = false diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index 65d8dbf9..92dd08a2 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -61,6 +61,7 @@ class Preferences: Codable, ObservableObject { } self.blurMediaBehindContentWarning = try container.decodeIfPresent(Bool.self, forKey: .blurMediaBehindContentWarning) ?? true self.automaticallyPlayGifs = try container.decode(Bool.self, forKey: .automaticallyPlayGifs) + self.showUncroppedMediaInline = try container.decodeIfPresent(Bool.self, forKey: .showUncroppedMediaInline) ?? true self.openLinksInApps = try container.decode(Bool.self, forKey: .openLinksInApps) self.useInAppSafari = try container.decode(Bool.self, forKey: .useInAppSafari) @@ -108,6 +109,7 @@ class Preferences: Codable, ObservableObject { try container.encode(attachmentBlurMode, forKey: .attachmentBlurMode) try container.encode(blurMediaBehindContentWarning, forKey: .blurMediaBehindContentWarning) try container.encode(automaticallyPlayGifs, forKey: .automaticallyPlayGifs) + try container.encode(showUncroppedMediaInline, forKey: .showUncroppedMediaInline) try container.encode(openLinksInApps, forKey: .openLinksInApps) try container.encode(useInAppSafari, forKey: .useInAppSafari) @@ -163,6 +165,7 @@ class Preferences: Codable, ObservableObject { } @Published var blurMediaBehindContentWarning = true @Published var automaticallyPlayGifs = true + @Published var showUncroppedMediaInline = true // MARK: Behavior @Published var openLinksInApps = true @@ -213,6 +216,7 @@ class Preferences: Codable, ObservableObject { case attachmentBlurMode case blurMediaBehindContentWarning case automaticallyPlayGifs + case showUncroppedMediaInline case openLinksInApps case useInAppSafari diff --git a/Tusker/Screens/Preferences/MediaPrefsView.swift b/Tusker/Screens/Preferences/MediaPrefsView.swift index 92b12301..aa84b4e0 100644 --- a/Tusker/Screens/Preferences/MediaPrefsView.swift +++ b/Tusker/Screens/Preferences/MediaPrefsView.swift @@ -37,6 +37,10 @@ struct MediaPrefsView: View { Toggle(isOn: $preferences.automaticallyPlayGifs) { Text("Automatically Play GIFs") } + + Toggle(isOn: $preferences.showUncroppedMediaInline) { + Text("Show Uncropped Media Inline") + } } } } diff --git a/Tusker/Views/Attachments/AttachmentView.swift b/Tusker/Views/Attachments/AttachmentView.swift index 3fd8f93a..6789b36c 100644 --- a/Tusker/Views/Attachments/AttachmentView.swift +++ b/Tusker/Views/Attachments/AttachmentView.swift @@ -141,17 +141,20 @@ class AttachmentView: GIFImageView { } } - private func blurHashSize() -> CGSize { + var attachmentAspectRatio: CGFloat? { if let meta = self.attachment.meta { - let aspectRatio: CGFloat if let width = meta.width, let height = meta.height { - aspectRatio = CGFloat(width) / CGFloat(height) + return CGFloat(width) / CGFloat(height) } else if let orig = meta.original, let width = orig.width, let height = orig.height { - aspectRatio = CGFloat(width) / CGFloat(height) - } else { - return CGSize(width: 32, height: 32) + return CGFloat(width) / CGFloat(height) } + } + return nil + } + + private func blurHashSize() -> CGSize { + if let aspectRatio = attachmentAspectRatio { if aspectRatio > 1 { return CGSize(width: 32, height: 32 / aspectRatio) } else { diff --git a/Tusker/Views/Attachments/AttachmentsContainerView.swift b/Tusker/Views/Attachments/AttachmentsContainerView.swift index 1ce11f62..c5f02d54 100644 --- a/Tusker/Views/Attachments/AttachmentsContainerView.swift +++ b/Tusker/Views/Attachments/AttachmentsContainerView.swift @@ -21,6 +21,7 @@ class AttachmentsContainerView: UIView { let attachmentViews: NSHashTable = .weakObjects() let attachmentStacks: NSHashTable = .weakObjects() var moreView: UIView? + private var aspectRatioConstraint: NSLayoutConstraint? var blurView: UIVisualEffectView? var hideButtonView: UIVisualEffectView? @@ -78,6 +79,8 @@ class AttachmentsContainerView: UIView { if attachments.count > 0 { self.isHidden = false + var aspectRatio: CGFloat = 16/9 + switch attachments.count { case 1: let attachmentView = createAttachmentView(index: 0, hSize: .full, vSize: .full) @@ -86,6 +89,9 @@ class AttachmentsContainerView: UIView { fillView(attachmentView) sendSubviewToBack(attachmentView) accessibilityElements.append(attachmentView) + if let attachmentAspectRatio = attachmentView.attachmentAspectRatio { + aspectRatio = attachmentAspectRatio + } case 2: let left = createAttachmentView(index: 0, hSize: .half, vSize: .full) left.layer.cornerRadius = 5 @@ -242,7 +248,19 @@ class AttachmentsContainerView: UIView { accessibilityElements.append(topRight) accessibilityElements.append(bottomLeft) accessibilityElements.append(moreView) - + } + + if Preferences.shared.showUncroppedMediaInline { + if aspectRatioConstraint?.multiplier != aspectRatio { + aspectRatioConstraint?.isActive = false + aspectRatioConstraint = widthAnchor.constraint(equalTo: heightAnchor, multiplier: aspectRatio) + aspectRatioConstraint!.isActive = true + } + } else { + if aspectRatioConstraint == nil { + aspectRatioConstraint = widthAnchor.constraint(equalTo: heightAnchor, multiplier: 16/9) + aspectRatioConstraint!.isActive = true + } } } else { self.isHidden = true diff --git a/Tusker/Views/Status/ConversationMainStatusTableViewCell.xib b/Tusker/Views/Status/ConversationMainStatusTableViewCell.xib index cbd1962a..d1522afa 100644 --- a/Tusker/Views/Status/ConversationMainStatusTableViewCell.xib +++ b/Tusker/Views/Status/ConversationMainStatusTableViewCell.xib @@ -104,9 +104,6 @@ diff --git a/Tusker/Views/Status/StatusCollectionViewCell.swift b/Tusker/Views/Status/StatusCollectionViewCell.swift index 9e48ab18..52ab6e58 100644 --- a/Tusker/Views/Status/StatusCollectionViewCell.swift +++ b/Tusker/Views/Status/StatusCollectionViewCell.swift @@ -107,7 +107,7 @@ extension StatusCollectionViewCell { if statusState.unknown { // layout so that we can take the content height into consideration when deciding whether to collapse layoutIfNeeded() - statusState.resolveFor(status: status, height: contentContainer.contentTextView.bounds.height) + statusState.resolveFor(status: status, height: contentContainer.visibleSubviewHeight) if statusState.collapsible! && showStatusAutomatically { statusState.collapsed = false } diff --git a/Tusker/Views/Status/StatusContentContainer.swift b/Tusker/Views/Status/StatusContentContainer.swift index cdb4a7fe..e60fa6cf 100644 --- a/Tusker/Views/Status/StatusContentContainer.swift +++ b/Tusker/Views/Status/StatusContentContainer.swift @@ -24,11 +24,7 @@ class StatusContentContainer: UIView { ]) } - let attachmentsView = AttachmentsContainerView().configure { - NSLayoutConstraint.activate([ - $0.heightAnchor.constraint(equalTo: $0.widthAnchor, multiplier: 9/16), - ]) - } + let attachmentsView = AttachmentsContainerView() let pollView = StatusPollView() @@ -43,6 +39,10 @@ class StatusContentContainer: UIView { private var zeroHeightConstraint: NSLayoutConstraint! private var isCollapsed = false + + var visibleSubviewHeight: CGFloat { + subviews.filter { !$0.isHidden }.map(\.bounds.height).reduce(0, +) + } override init(frame: CGRect) { super.init(frame: frame) diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.xib b/Tusker/Views/Status/TimelineStatusTableViewCell.xib index 3a26abf2..3f5fa713 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.xib +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.xib @@ -1,9 +1,9 @@ - + - + @@ -132,9 +132,6 @@