Show individual attachments uncropped inline in statuses

This commit is contained in:
Shadowfacts 2022-12-25 14:13:59 -05:00
parent 15a7cd5f65
commit 16cd045588
9 changed files with 45 additions and 22 deletions

View File

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

View File

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

View File

@ -37,6 +37,10 @@ struct MediaPrefsView: View {
Toggle(isOn: $preferences.automaticallyPlayGifs) {
Text("Automatically Play GIFs")
}
Toggle(isOn: $preferences.showUncroppedMediaInline) {
Text("Show Uncropped Media Inline")
}
}
}
}

View File

@ -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 {

View File

@ -21,6 +21,7 @@ class AttachmentsContainerView: UIView {
let attachmentViews: NSHashTable<AttachmentView> = .weakObjects()
let attachmentStacks: NSHashTable<UIStackView> = .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

View File

@ -104,9 +104,6 @@
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="IF9-9U-Gk0" customClass="AttachmentsContainerView" customModule="Tusker" customModuleProvider="target">
<rect key="frame" x="0.0" y="128.5" width="343" height="0.0"/>
<color key="backgroundColor" systemColor="secondarySystemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" secondItem="IF9-9U-Gk0" secondAttribute="width" multiplier="9:16" priority="999" id="5oh-eK-J5d"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="TLv-Xu-tT1" customClass="StatusPollView" customModule="Tusker" customModuleProvider="target">
<rect key="frame" x="0.0" y="132.5" width="343" height="39.5"/>

View File

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

View File

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

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21225" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21207"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@ -132,9 +132,6 @@
<view hidden="YES" contentMode="scaleToFill" verticalCompressionResistancePriority="1" translatesAutoresizingMaskIntoConstraints="NO" id="nbq-yr-2mA" customClass="AttachmentsContainerView" customModule="Tusker" customModuleProvider="target">
<rect key="frame" x="0.0" y="171.5" width="277" height="0.0"/>
<color key="backgroundColor" systemColor="secondarySystemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" secondItem="nbq-yr-2mA" secondAttribute="width" multiplier="9:16" priority="999" id="Rvt-zs-fkd"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="x3b-Zl-9F0" customClass="StatusPollView" customModule="Tusker" customModuleProvider="target">
<rect key="frame" x="0.0" y="173.5" width="277" height="0.0"/>