diff --git a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift index c34650adb1..8805e31aea 100644 --- a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift +++ b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift @@ -16,6 +16,7 @@ class ActionNotificationGroupTableViewCell: UITableViewCell { var mastodonController: MastodonController! { delegate?.apiController } @IBOutlet weak var actionImageView: UIImageView! + @IBOutlet weak var verticalStackView: UIStackView! @IBOutlet weak var actionAvatarStackView: UIStackView! @IBOutlet weak var timestampLabel: UILabel! @IBOutlet weak var actionLabel: UILabel! @@ -70,6 +71,7 @@ class ActionNotificationGroupTableViewCell: UITableViewCell { let people = group.notificationIDs.compactMap(mastodonController.cache.notification(for:)).map { $0.account } actionAvatarStackView.arrangedSubviews.forEach { $0.removeFromSuperview() } + var imageViews = [UIImageView]() for account in people { let imageView = UIImageView() imageView.translatesAutoresizingMaskIntoConstraints = false @@ -83,12 +85,19 @@ class ActionNotificationGroupTableViewCell: UITableViewCell { } } actionAvatarStackView.addArrangedSubview(imageView) - NSLayoutConstraint.activate([ - imageView.widthAnchor.constraint(equalToConstant: 30), - imageView.heightAnchor.constraint(equalToConstant: 30) - ]) + imageViews.append(imageView) + + // don't add more avatars if they would overflow or squeeze the timestamp label + let avatarViewsWidth = 30 * CGFloat(imageViews.count) + let avatarMarginsWidth = 4 * CGFloat(max(0, imageViews.count - 1)) + let maxAvatarStackWidth = verticalStackView.bounds.width - timestampLabel.bounds.width - 8 + let remainingWidth = maxAvatarStackWidth - avatarViewsWidth - avatarMarginsWidth + if remainingWidth < 34 { + break + } } - + NSLayoutConstraint.activate(imageViews.map { $0.widthAnchor.constraint(equalTo: $0.heightAnchor) }) + updateTimestamp() updateActionLabel(people: people) diff --git a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.xib b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.xib index b9c06cdb37..cc42d57c56 100644 --- a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.xib +++ b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.xib @@ -1,8 +1,8 @@ - + - + @@ -19,19 +19,19 @@ - + - - + + - + -