|
|
|
@ -8,8 +8,8 @@ public class MediaAlbumView: UIStackView {
|
|
|
|
|
public let itemViews: [MediaView]
|
|
|
|
|
public var moreItemsView: MediaView?
|
|
|
|
|
|
|
|
|
|
private static let kSpacingPts: CGFloat = 2
|
|
|
|
|
private static let kMaxItems = 5
|
|
|
|
|
private static let kSpacingPts: CGFloat = 4
|
|
|
|
|
private static let kMaxItems = 3
|
|
|
|
|
|
|
|
|
|
@available(*, unavailable, message: "use other init() instead.")
|
|
|
|
|
required public init(coder aDecoder: NSCoder) {
|
|
|
|
@ -65,8 +65,8 @@ public class MediaAlbumView: UIStackView {
|
|
|
|
|
self.axis = .horizontal
|
|
|
|
|
self.distribution = .fillEqually
|
|
|
|
|
self.spacing = MediaAlbumView.kSpacingPts
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
// x
|
|
|
|
|
// X x
|
|
|
|
|
// Big on left, 2 small on right.
|
|
|
|
@ -90,64 +90,9 @@ public class MediaAlbumView: UIStackView {
|
|
|
|
|
)
|
|
|
|
|
self.axis = .horizontal
|
|
|
|
|
self.spacing = MediaAlbumView.kSpacingPts
|
|
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
// X X
|
|
|
|
|
// X X
|
|
|
|
|
// Square
|
|
|
|
|
let imageSize = (maxMessageWidth - MediaAlbumView.kSpacingPts) / 2
|
|
|
|
|
|
|
|
|
|
let topViews = Array(itemViews[0..<2])
|
|
|
|
|
addArrangedSubview(
|
|
|
|
|
newRow(
|
|
|
|
|
rowViews: topViews,
|
|
|
|
|
axis: .horizontal,
|
|
|
|
|
viewSize: imageSize
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
let bottomViews = Array(itemViews[2..<4])
|
|
|
|
|
addArrangedSubview(
|
|
|
|
|
newRow(
|
|
|
|
|
rowViews: bottomViews,
|
|
|
|
|
axis: .horizontal,
|
|
|
|
|
viewSize: imageSize
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.axis = .vertical
|
|
|
|
|
self.spacing = MediaAlbumView.kSpacingPts
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
// X X
|
|
|
|
|
// xxx
|
|
|
|
|
// 2 big on top, 3 small on bottom.
|
|
|
|
|
let bigImageSize = (maxMessageWidth - MediaAlbumView.kSpacingPts) / 2
|
|
|
|
|
let smallImageSize = (maxMessageWidth - MediaAlbumView.kSpacingPts * 2) / 3
|
|
|
|
|
|
|
|
|
|
let topViews = Array(itemViews[0..<2])
|
|
|
|
|
addArrangedSubview(
|
|
|
|
|
newRow(
|
|
|
|
|
rowViews: topViews,
|
|
|
|
|
axis: .horizontal,
|
|
|
|
|
viewSize: bigImageSize
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
let bottomViews = Array(itemViews[2..<5])
|
|
|
|
|
addArrangedSubview(
|
|
|
|
|
newRow(
|
|
|
|
|
rowViews: bottomViews,
|
|
|
|
|
axis: .horizontal,
|
|
|
|
|
viewSize: smallImageSize
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.axis = .vertical
|
|
|
|
|
self.spacing = MediaAlbumView.kSpacingPts
|
|
|
|
|
|
|
|
|
|
if items.count > MediaAlbumView.kMaxItems {
|
|
|
|
|
guard let lastView = bottomViews.last else {
|
|
|
|
|
guard let lastView = rightViews.last else {
|
|
|
|
|
owsFailDebug("Missing lastView")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -263,13 +208,8 @@ public class MediaAlbumView: UIStackView {
|
|
|
|
|
let itemCount = itemsToDisplay(forItems: items).count
|
|
|
|
|
|
|
|
|
|
switch itemCount {
|
|
|
|
|
case 0, 1, 4:
|
|
|
|
|
case 0, 1:
|
|
|
|
|
// X
|
|
|
|
|
//
|
|
|
|
|
// or
|
|
|
|
|
//
|
|
|
|
|
// XX
|
|
|
|
|
// XX
|
|
|
|
|
// Square
|
|
|
|
|
return CGSize(width: maxMessageWidth, height: maxMessageWidth)
|
|
|
|
|
|
|
|
|
@ -279,21 +219,13 @@ public class MediaAlbumView: UIStackView {
|
|
|
|
|
let imageSize = (maxMessageWidth - kSpacingPts) / 2
|
|
|
|
|
return CGSize(width: maxMessageWidth, height: imageSize)
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
default:
|
|
|
|
|
// x
|
|
|
|
|
// X x
|
|
|
|
|
// Big on left, 2 small on right.
|
|
|
|
|
let smallImageSize = (maxMessageWidth - kSpacingPts * 2) / 3
|
|
|
|
|
let bigImageSize = smallImageSize * 2 + kSpacingPts
|
|
|
|
|
return CGSize(width: maxMessageWidth, height: bigImageSize)
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
// X X
|
|
|
|
|
// xxx
|
|
|
|
|
// 2 big on top, 3 small on bottom.
|
|
|
|
|
let bigImageSize = (maxMessageWidth - kSpacingPts) / 2
|
|
|
|
|
let smallImageSize = (maxMessageWidth - kSpacingPts * 2) / 3
|
|
|
|
|
return CGSize(width: maxMessageWidth, height: bigImageSize + smallImageSize + kSpacingPts)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|