mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-19 08:03:50 +02:00
Reduce the width of URL previews on 4" devices.
This commit is contained in:
@@ -33,6 +33,8 @@ class URLPreviewView: UIView, NibLoadable, Themable {
|
||||
private enum Constants {
|
||||
/// The fixed width of the preview view.
|
||||
static let width: CGFloat = 267.0
|
||||
/// A reduced width available for use on 4" devices.
|
||||
static let reducedWidth: CGFloat = 230
|
||||
}
|
||||
|
||||
// MARK: - Properties
|
||||
@@ -48,22 +50,33 @@ class URLPreviewView: UIView, NibLoadable, Themable {
|
||||
}
|
||||
}
|
||||
|
||||
/// The total width available for the view to layout.
|
||||
/// Note: The view's width will be the largest `Constant` that fits this size.
|
||||
var availableWidth: CGFloat = 375 {
|
||||
didSet {
|
||||
// TODO: adjust values when using RoomBubbleCellData's maxTextViewWidth property
|
||||
widthConstraint.constant = availableWidth <= 320 ? Constants.reducedWidth : Constants.width
|
||||
}
|
||||
}
|
||||
|
||||
weak var delegate: URLPreviewViewDelegate?
|
||||
|
||||
@IBOutlet weak var imageView: UIImageView!
|
||||
@IBOutlet weak var closeButton: UIButton!
|
||||
@IBOutlet private weak var imageView: UIImageView!
|
||||
@IBOutlet private weak var closeButton: UIButton!
|
||||
|
||||
@IBOutlet weak var textContainerView: UIView!
|
||||
@IBOutlet weak var siteNameLabel: UILabel!
|
||||
@IBOutlet weak var titleLabel: UILabel!
|
||||
@IBOutlet weak var descriptionLabel: UILabel!
|
||||
@IBOutlet private weak var textContainerView: UIView!
|
||||
@IBOutlet private weak var siteNameLabel: UILabel!
|
||||
@IBOutlet private weak var titleLabel: UILabel!
|
||||
@IBOutlet private weak var descriptionLabel: UILabel!
|
||||
|
||||
@IBOutlet weak var loadingView: UIView!
|
||||
@IBOutlet weak var loadingActivityIndicator: UIActivityIndicatorView!
|
||||
@IBOutlet private weak var loadingView: UIView!
|
||||
@IBOutlet private weak var loadingActivityIndicator: UIActivityIndicatorView!
|
||||
|
||||
// The constraint that determines the view's width
|
||||
@IBOutlet private weak var widthConstraint: NSLayoutConstraint!
|
||||
// Matches the label's height with the close button.
|
||||
// Use a strong reference to keep it around when deactivating.
|
||||
@IBOutlet var siteNameLabelHeightConstraint: NSLayoutConstraint!
|
||||
@IBOutlet private var siteNameLabelHeightConstraint: NSLayoutConstraint!
|
||||
|
||||
/// Returns true when `titleLabel` has a non-empty string.
|
||||
private var hasTitle: Bool {
|
||||
@@ -114,8 +127,9 @@ class URLPreviewView: UIView, NibLoadable, Themable {
|
||||
closeButton.setImage(closeButtonAsset.image, for: .normal)
|
||||
}
|
||||
|
||||
static func contentViewHeight(for preview: URLPreviewData?) -> CGFloat {
|
||||
sizingView.frame = CGRect(x: 0, y: 0, width: Constants.width, height: 1)
|
||||
static func contentViewHeight(for preview: URLPreviewData?, fitting maxWidth: CGFloat) -> CGFloat {
|
||||
sizingView.availableWidth = maxWidth
|
||||
sizingView.frame = CGRect(x: 0, y: 0, width: sizingView.widthConstraint.constant, height: 1)
|
||||
|
||||
// Call render directly to avoid storing the preview data in the sizing view
|
||||
if let preview = preview {
|
||||
@@ -127,7 +141,7 @@ class URLPreviewView: UIView, NibLoadable, Themable {
|
||||
sizingView.setNeedsLayout()
|
||||
sizingView.layoutIfNeeded()
|
||||
|
||||
let fittingSize = CGSize(width: Constants.width, height: UIView.layoutFittingCompressedSize.height)
|
||||
let fittingSize = CGSize(width: sizingView.widthConstraint.constant, height: UIView.layoutFittingCompressedSize.height)
|
||||
let layoutSize = sizingView.systemLayoutSizeFitting(fittingSize)
|
||||
|
||||
return layoutSize.height
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="4zc-0W-jb8">
|
||||
<rect key="frame" x="0.0" y="0.0" width="267" height="140"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="140" id="QpS-Ys-x5s"/>
|
||||
<constraint firstAttribute="width" secondItem="4zc-0W-jb8" secondAttribute="height" multiplier="267:140" id="0xq-yj-vni"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="n9x-Yn-0qQ" userLabel="Text Container">
|
||||
@@ -109,6 +109,7 @@
|
||||
<outlet property="siteNameLabelHeightConstraint" destination="vhD-hz-f58" id="Bz9-ub-9UA"/>
|
||||
<outlet property="textContainerView" destination="n9x-Yn-0qQ" id="Zul-rd-vrp"/>
|
||||
<outlet property="titleLabel" destination="IVX-5S-0kr" id="PRN-5g-HiO"/>
|
||||
<outlet property="widthConstraint" destination="f2o-yq-NFO" id="bn0-wB-66e"/>
|
||||
<outletCollection property="gestureRecognizers" destination="rSB-1V-Kev" appends="YES" id="OOJ-ft-VIj"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="1852.8985507246377" y="14.397321428571427"/>
|
||||
|
||||
Reference in New Issue
Block a user