diff --git a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift index 24c297cc..f5ade795 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! @@ -71,6 +72,7 @@ class ActionNotificationGroupTableViewCell: UITableViewCell { let people = group.notifications.compactMap { mastodonController.persistentContainer.account(for: $0.account.id) } actionAvatarStackView.arrangedSubviews.forEach { $0.removeFromSuperview() } + var imageViews = [UIImageView]() for account in people { let imageView = UIImageView() imageView.translatesAutoresizingMaskIntoConstraints = false @@ -84,12 +86,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 b9c06cdb..cc42d57c 100644 --- a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.xib +++ b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.xib @@ -1,8 +1,8 @@ - + - + @@ -19,19 +19,19 @@ - + - - + + - + -