From 9d245d3205293a2a22275055babc6532cc8c41d8 Mon Sep 17 00:00:00 2001 From: Marcus Kida Date: Wed, 23 Nov 2022 17:24:25 +0100 Subject: [PATCH] feat: Fix follow hashtags header layout --- .../HashtagTimeline/HashtagTimelineHeaderView.swift | 12 +++++++++++- .../HashtagTimelineViewController.swift | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Mastodon/Scene/HashtagTimeline/HashtagTimelineHeaderView.swift b/Mastodon/Scene/HashtagTimeline/HashtagTimelineHeaderView.swift index 80a6795f3..49442c03d 100644 --- a/Mastodon/Scene/HashtagTimeline/HashtagTimelineHeaderView.swift +++ b/Mastodon/Scene/HashtagTimeline/HashtagTimelineHeaderView.swift @@ -25,6 +25,8 @@ final class HashtagTimelineHeaderView: UIView { let participantsDescLabel = UILabel() let postsTodayDescLabel = UILabel() + private var widthConstraint: NSLayoutConstraint! + let followButton: UIButton = { let button = RoundedEdgesButton(type: .custom) button.cornerRadius = 10 @@ -67,8 +69,12 @@ private extension HashtagTimelineHeaderView { postCountDescLabel.text = "posts" participantsDescLabel.text = "participants" postsTodayDescLabel.text = "posts today" - + + widthConstraint = widthAnchor.constraint(equalToConstant: 0) + NSLayoutConstraint.activate([ + widthConstraint, + titleLabel.topAnchor.constraint(equalTo: topAnchor, constant: .padding), titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: .padding), titleLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -CGFloat.padding), @@ -106,4 +112,8 @@ extension HashtagTimelineHeaderView { titleLabel.text = "#\(entity.name)" followButton.setTitle(entity.following == true ? "Unfollow" : "Follow", for: .normal) } + + func updateWidthConstraint(_ constant: CGFloat) { + widthConstraint.constant = constant + } } diff --git a/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewController.swift b/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewController.swift index d48220615..8d79b0ed1 100644 --- a/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewController.swift +++ b/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewController.swift @@ -178,6 +178,11 @@ extension HashtagTimelineViewController { } headerView.update(tag) } + + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + headerView.updateWidthConstraint(tableView.bounds.width) + } } extension HashtagTimelineViewController {