diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.m b/Riot/Modules/Room/DataSources/RoomDataSource.m
index b8b58d61c..d2a3ab48b 100644
--- a/Riot/Modules/Room/DataSources/RoomDataSource.m
+++ b/Riot/Modules/Room/DataSources/RoomDataSource.m
@@ -388,6 +388,8 @@ const CGFloat kTypingCellHeight = 24;
[bubbleCell.tmpSubviews addObject:urlPreviewView];
urlPreviewView.translatesAutoresizingMaskIntoConstraints = NO;
+ // TODO: Use cellData.maxTextViewWidth when the view height is part of RoomBubbleCellData's additional height.
+ urlPreviewView.availableWidth = tableView.contentSize.width;
[bubbleCell.contentView addSubview:urlPreviewView];
CGFloat leftMargin = RoomBubbleCellLayout.reactionsViewLeftMargin;
diff --git a/Riot/Modules/Room/Views/BubbleCells/RoomIncomingTextMsgBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/RoomIncomingTextMsgBubbleCell.m
index 542f20a44..9ab51781e 100644
--- a/Riot/Modules/Room/Views/BubbleCells/RoomIncomingTextMsgBubbleCell.m
+++ b/Riot/Modules/Room/Views/BubbleCells/RoomIncomingTextMsgBubbleCell.m
@@ -47,7 +47,8 @@
if (RiotSettings.shared.roomScreenShowsURLPreviews && bubbleData && bubbleData.showURLPreview)
{
CGFloat height = [super heightForCellData:cellData withMaximumWidth:maxWidth];
- return height + RoomBubbleCellLayout.urlPreviewViewTopMargin + [URLPreviewView contentViewHeightFor:bubbleData.urlPreviewData];
+ return height + RoomBubbleCellLayout.urlPreviewViewTopMargin + [URLPreviewView contentViewHeightFor:bubbleData.urlPreviewData
+ fitting:maxWidth];
}
return [super heightForCellData:cellData withMaximumWidth:maxWidth];
diff --git a/Riot/Modules/Room/Views/BubbleCells/RoomIncomingTextMsgWithPaginationTitleBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/RoomIncomingTextMsgWithPaginationTitleBubbleCell.m
index af187513b..9a6185998 100644
--- a/Riot/Modules/Room/Views/BubbleCells/RoomIncomingTextMsgWithPaginationTitleBubbleCell.m
+++ b/Riot/Modules/Room/Views/BubbleCells/RoomIncomingTextMsgWithPaginationTitleBubbleCell.m
@@ -53,7 +53,8 @@
if (RiotSettings.shared.roomScreenShowsURLPreviews && bubbleData && bubbleData.showURLPreview)
{
CGFloat height = [super heightForCellData:cellData withMaximumWidth:maxWidth];
- return height + RoomBubbleCellLayout.urlPreviewViewTopMargin + [URLPreviewView contentViewHeightFor:bubbleData.urlPreviewData];
+ return height + RoomBubbleCellLayout.urlPreviewViewTopMargin + [URLPreviewView contentViewHeightFor:bubbleData.urlPreviewData
+ fitting:maxWidth];
}
return [super heightForCellData:cellData withMaximumWidth:maxWidth];
diff --git a/Riot/Modules/Room/Views/BubbleCells/RoomIncomingTextMsgWithoutSenderInfoBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/RoomIncomingTextMsgWithoutSenderInfoBubbleCell.m
index 19fb4a5cd..599940a69 100644
--- a/Riot/Modules/Room/Views/BubbleCells/RoomIncomingTextMsgWithoutSenderInfoBubbleCell.m
+++ b/Riot/Modules/Room/Views/BubbleCells/RoomIncomingTextMsgWithoutSenderInfoBubbleCell.m
@@ -37,7 +37,8 @@
if (RiotSettings.shared.roomScreenShowsURLPreviews && bubbleData && bubbleData.showURLPreview)
{
CGFloat height = [super heightForCellData:cellData withMaximumWidth:maxWidth];
- return height + RoomBubbleCellLayout.urlPreviewViewTopMargin + [URLPreviewView contentViewHeightFor:bubbleData.urlPreviewData];
+ return height + RoomBubbleCellLayout.urlPreviewViewTopMargin + [URLPreviewView contentViewHeightFor:bubbleData.urlPreviewData
+ fitting:maxWidth];
}
return [super heightForCellData:cellData withMaximumWidth:maxWidth];
diff --git a/Riot/Modules/Room/Views/BubbleCells/RoomOutgoingTextMsgBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/RoomOutgoingTextMsgBubbleCell.m
index 94bd5c310..e2e39e2ef 100644
--- a/Riot/Modules/Room/Views/BubbleCells/RoomOutgoingTextMsgBubbleCell.m
+++ b/Riot/Modules/Room/Views/BubbleCells/RoomOutgoingTextMsgBubbleCell.m
@@ -48,7 +48,8 @@
if (RiotSettings.shared.roomScreenShowsURLPreviews && bubbleData && bubbleData.showURLPreview)
{
CGFloat height = [super heightForCellData:cellData withMaximumWidth:maxWidth];
- return height + RoomBubbleCellLayout.urlPreviewViewTopMargin + [URLPreviewView contentViewHeightFor:bubbleData.urlPreviewData];
+ return height + RoomBubbleCellLayout.urlPreviewViewTopMargin + [URLPreviewView contentViewHeightFor:bubbleData.urlPreviewData
+ fitting:maxWidth];
}
return [super heightForCellData:cellData withMaximumWidth:maxWidth];
diff --git a/Riot/Modules/Room/Views/BubbleCells/RoomOutgoingTextMsgWithoutSenderInfoBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/RoomOutgoingTextMsgWithoutSenderInfoBubbleCell.m
index 0c444d51f..d90f4eea4 100644
--- a/Riot/Modules/Room/Views/BubbleCells/RoomOutgoingTextMsgWithoutSenderInfoBubbleCell.m
+++ b/Riot/Modules/Room/Views/BubbleCells/RoomOutgoingTextMsgWithoutSenderInfoBubbleCell.m
@@ -37,7 +37,8 @@
if (RiotSettings.shared.roomScreenShowsURLPreviews && bubbleData && bubbleData.showURLPreview)
{
CGFloat height = [super heightForCellData:cellData withMaximumWidth:maxWidth];
- return height + RoomBubbleCellLayout.urlPreviewViewTopMargin + [URLPreviewView contentViewHeightFor:bubbleData.urlPreviewData];
+ return height + RoomBubbleCellLayout.urlPreviewViewTopMargin + [URLPreviewView contentViewHeightFor:bubbleData.urlPreviewData
+ fitting:maxWidth];
}
return [super heightForCellData:cellData withMaximumWidth:maxWidth];
diff --git a/Riot/Modules/Room/Views/URLPreviews/URLPreviewView.swift b/Riot/Modules/Room/Views/URLPreviews/URLPreviewView.swift
index e36759bc5..2b661e0e4 100644
--- a/Riot/Modules/Room/Views/URLPreviews/URLPreviewView.swift
+++ b/Riot/Modules/Room/Views/URLPreviews/URLPreviewView.swift
@@ -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
diff --git a/Riot/Modules/Room/Views/URLPreviews/URLPreviewView.xib b/Riot/Modules/Room/Views/URLPreviews/URLPreviewView.xib
index a65c9d192..1f1e9aba9 100644
--- a/Riot/Modules/Room/Views/URLPreviews/URLPreviewView.xib
+++ b/Riot/Modules/Room/Views/URLPreviews/URLPreviewView.xib
@@ -19,7 +19,7 @@
-
+
@@ -109,6 +109,7 @@
+