From aad592e01a35bda7e8376c6f6e718caec0dcf09b Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Sun, 31 Jan 2021 10:43:37 -0800 Subject: [PATCH] Follows you indicator --- Localizations/Localizable.strings | 1 + Metatext.xcodeproj/project.pbxproj | 4 +++ Views/UIKit/AccountHeaderView.swift | 7 +++++ Views/UIKit/FollowsYouLabel.swift | 49 +++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 Views/UIKit/FollowsYouLabel.swift diff --git a/Localizations/Localizable.strings b/Localizations/Localizable.strings index 60460f1..9005f6b 100644 --- a/Localizations/Localizable.strings +++ b/Localizations/Localizable.strings @@ -14,6 +14,7 @@ "account.following" = "Following"; "account.following-count" = "%ld Following"; "account.followed-by-%@" = "Followed by %@"; +"account.follows-you" = "Follows you"; "account.hide-reblogs" = "Hide boosts"; "account.mute" = "Mute"; "account.request" = "Request"; diff --git a/Metatext.xcodeproj/project.pbxproj b/Metatext.xcodeproj/project.pbxproj index e5800e5..5e883d3 100644 --- a/Metatext.xcodeproj/project.pbxproj +++ b/Metatext.xcodeproj/project.pbxproj @@ -58,6 +58,7 @@ D03D87F425C23C44004DCBB2 /* SecondaryNavigationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D03D87F325C23C44004DCBB2 /* SecondaryNavigationTitleView.swift */; }; D0477F1525C68BAC005C5368 /* PrefetchRequestModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0477F1425C68BAC005C5368 /* PrefetchRequestModifier.swift */; }; D0477F2C25C6EBAD005C5368 /* OpenInSafariActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0477F2B25C6EBAD005C5368 /* OpenInSafariActivity.swift */; }; + D0477F4625C72E50005C5368 /* FollowsYouLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0477F4525C72E50005C5368 /* FollowsYouLabel.swift */; }; D04F9E8E259E9C950081B0C9 /* ViewModels in Frameworks */ = {isa = PBXBuildFile; productRef = D04F9E8D259E9C950081B0C9 /* ViewModels */; }; D05936CF25A8D79800754FDF /* EditAttachmentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05936CE25A8D79800754FDF /* EditAttachmentViewController.swift */; }; D05936D025A8D79800754FDF /* EditAttachmentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05936CE25A8D79800754FDF /* EditAttachmentViewController.swift */; }; @@ -255,6 +256,7 @@ D03D87F325C23C44004DCBB2 /* SecondaryNavigationTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondaryNavigationTitleView.swift; sourceTree = ""; }; D0477F1425C68BAC005C5368 /* PrefetchRequestModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefetchRequestModifier.swift; sourceTree = ""; }; D0477F2B25C6EBAD005C5368 /* OpenInSafariActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenInSafariActivity.swift; sourceTree = ""; }; + D0477F4525C72E50005C5368 /* FollowsYouLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowsYouLabel.swift; sourceTree = ""; }; D047FA8C24C3E21200AF17C5 /* Metatext.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Metatext.app; sourceTree = BUILT_PRODUCTS_DIR; }; D05936CE25A8D79800754FDF /* EditAttachmentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditAttachmentViewController.swift; sourceTree = ""; }; D05936DD25A937EC00754FDF /* EditThumbnailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditThumbnailView.swift; sourceTree = ""; }; @@ -434,6 +436,7 @@ D05936DD25A937EC00754FDF /* EditThumbnailView.swift */, D07EC7FC25B16994006DF726 /* EmojiCategoryHeaderView.swift */, D0DDA77E25C6058300FA0F91 /* ExploreSectionHeaderView.swift */, + D0477F4525C72E50005C5368 /* FollowsYouLabel.swift */, D0D2AC6625BD0484003D5DF2 /* LineChartView.swift */, D0BEB1F624F9A84B001B0F04 /* LoadingTableFooterView.swift */, D05936FE25AA94EA00754FDF /* MarkAttachmentsSensitiveView.swift */, @@ -1071,6 +1074,7 @@ D0E1F583251F13EC00D45315 /* WebfingerIndicatorView.swift in Sources */, D0BEB20524FA1107001B0F04 /* FiltersView.swift in Sources */, D0DDA76B25C5F20800FA0F91 /* ExploreDataSource.swift in Sources */, + D0477F4625C72E50005C5368 /* FollowsYouLabel.swift in Sources */, D035F88725B8016000DC75ED /* NavigationViewModel+Extensions.swift in Sources */, D0C7D49B24F7616A001EBDBB /* PreferencesView.swift in Sources */, D09D972225C65682007E6394 /* SeparatorConfiguredCollectionViewListCell.swift in Sources */, diff --git a/Views/UIKit/AccountHeaderView.swift b/Views/UIKit/AccountHeaderView.swift index 739642d..d9bf293 100644 --- a/Views/UIKit/AccountHeaderView.swift +++ b/Views/UIKit/AccountHeaderView.swift @@ -18,6 +18,7 @@ final class AccountHeaderView: UIView { let accountStackView = UIStackView() let accountLabel = UILabel() let lockedImageView = UIImageView() + let followsYouLabel = FollowsYouLabel() let fieldsStackView = UIStackView() let noteTextView = TouchFallthroughTextView() let followStackView = UIStackView() @@ -39,6 +40,7 @@ final class AccountHeaderView: UIView { avatarImageView.tag = accountViewModel.avatarURL(profile: true).hashValue if !accountViewModel.isSelf, let relationship = accountViewModel.relationship { + followsYouLabel.isHidden = !relationship.followedBy followButton.setTitle( NSLocalizedString( accountViewModel.isLocked ? "account.request" : "account.follow", @@ -267,6 +269,7 @@ private extension AccountHeaderView { displayNameLabel.adjustsFontForContentSizeCategory = true baseStackView.addArrangedSubview(accountStackView) + accountStackView.spacing = .compactSpacing accountStackView.addArrangedSubview(accountLabel) accountLabel.numberOfLines = 0 @@ -283,6 +286,10 @@ private extension AccountHeaderView { lockedImageView.tintColor = .secondaryLabel lockedImageView.contentMode = .scaleAspectFit + accountStackView.addArrangedSubview(followsYouLabel) + followsYouLabel.text = NSLocalizedString("account.follows-you", comment: "") + followsYouLabel.isHidden = true + accountStackView.addArrangedSubview(UIView()) baseStackView.addArrangedSubview(fieldsStackView) diff --git a/Views/UIKit/FollowsYouLabel.swift b/Views/UIKit/FollowsYouLabel.swift new file mode 100644 index 0000000..63c2c39 --- /dev/null +++ b/Views/UIKit/FollowsYouLabel.swift @@ -0,0 +1,49 @@ +// Copyright © 2021 Metabolist. All rights reserved. + +import UIKit + +final class FollowsYouLabel: UILabel { + override init(frame: CGRect) { + super.init(frame: frame) + + initialSetup() + } + + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func layoutSubviews() { + super.layoutSubviews() + + layer.cornerRadius = inset + invalidateIntrinsicContentSize() + } + + override func drawText(in rect: CGRect) { + super.drawText(in: rect.inset(by: .init(top: 0, left: inset, bottom: 0, right: inset))) + } + + override var intrinsicContentSize: CGSize { + var size = super.intrinsicContentSize + + size.width += inset * 2 + + return size + } +} + +private extension FollowsYouLabel { + var inset: CGFloat { bounds.height / 2 } + + func initialSetup() { + backgroundColor = .tertiarySystemBackground + textColor = .secondaryLabel + font = UIFont.preferredFont(forTextStyle: .footnote) + adjustsFontForContentSizeCategory = true + setContentHuggingPriority(.required, for: .horizontal) + setContentCompressionResistancePriority(.required, for: .horizontal) + clipsToBounds = true + } +}